Repositories
List remote repositories
Add new remote repository
|
git remote add <REMOTE_REPO_NAME> https://github.com/<OWNER>/<REPOSITORY>.git |
In case of fork, it’s useful to add the original repo as a remote repo named ‘upstream’
|
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git |
Sync fork repo with original repo
First, fetch original repo
Then, switch to fork/branch to sync with original branch (eg. master)
Merge original/branch with fork/branch
|
git merge upstream/master |
Finally, push synced fork/branch in remote fork/repo (eg. master)
Branches
List Branches
only local branches
both remote-tracking and local branches
Create new branch and switch to new Branch
Command
|
git checkout -b <branch_name> |
Clone a specific Branch
Command
|
git branch -a git checkout <name_of_branch> |
Create local Branch linked to remote Branch
Command
|
git branch -a git checkout -b <branch-name> <origin/branch_name> |
example
|
git branch -a * master origin/HEAD origin/enum-account-number origin/master origin/rel_table_play origin/sugarfield_customer_number_show_c |
|
git checkout -b enum-account-number origin/enum-account-number |
After you hit return the following happens:
|
Branch enum-account-number set up to track remote branch refs/remotes/origin/enum-account-number. Switched to a new branch "enum-account-number |
Switch Branch
Command
|
git checkout <branch_name> |
Remove Branch
remove local branch
|
git branch -d <branch_name> |
remove remote branch once removed local branch
|
git push origin :<branch_name> |
Push changes to Branch
Command
|
git push origin <branch_name> |
Merge Branches
swithc to destination branch
than commit selected branch into current branch
–no-ff option generate a merge commit with a message
|
git merge --no-ff <branch_name> |
Tags
List Tags
Command
Create Tag
Command
|
git tag <tag_name> <commit_id> |
commit id be retrieved via:
example
Push Tag
Push all tags
Push a single tag
|
git push origin <tag_name> |
Undo
Discharge changes on file or restore deleted file
|
git reset HEAD <file> git checkout <file> |
Undo a commit
reference
git – la guida tascabile