Heesung Yang
Git Branch Cheatsheet
Creating
-
creating branch from current commit
~$ git checkout -b <new branch> # example # branch name : my-branch ~$ git checkout -b my-branch
-
creating branch from specific tag
~$ git checkout -b <new branch> <tag> # example # branch name : my-branch # tag : 1.1.0 ~$ git checkout -b my-branch 1.1.0
-
pulling remote branch
~$ git checkout -b <local branch name> <remote branch name> # example # local branch name : local-my-branch # remote branch name : origin/my-branch ~$ git checkout -b local-my-branch origin/my-branch
-
pulling remote branch (using same branch name)
~$ git checkout -t <remote branch name> # example # remote name : origin # remote branch name : my-branch ~$ git checkout -t origin/my-branch
Listing
-
listing local branches
~$ git branch
-
listing remote branches
~$ git branch -r
-
listing local/remote branches
~$ git branch -a
Updating
-
pushing branch
~$ git push <remote name> <local branch name>:<remote branch name> # example # remote name : origin # local branch name : local-my-branch # remote branch name : my-branch ~$ git push origin local-my-branch:my-branch
-
pushing branch (using same branch name on remote)
~$ git push <remote name> <local branch name> # example # remote name : origin # branch name : my-branch ~$ git push origin my-branch
Delete
-
delete local branch
~$ git branch -d <branch_name> # example # branch name : my-branch ~$ git branch -d my-branch
-
delete remote branch
~$ git push <remote> :<branch_name> # example # remote name : origin # branch name : my-branch ~$ git push origin :my-branch