Skip to content

Git Branch

check branch

use git branch to see current branch

$ git branch
* master

add branch

add a branch name after git branch

$ git branch sidebranch

$ git branch
sidebranch
* master

# add branch with commit hash
$ git branch new_branch b174a5a

branch rename

$ git branch -m sidebranch tiger

$ git branch
tiger
* master

delete branch

$ git branch -d tiger

switch branch

$ git checkout cat
Switched to branch 'cat'

use -b option when the branch is not exist, it will auto create one new branch

merge branch

$ git checkout master
Switched to branch 'master'

$ git merge cat

notice: delete a branch will not remove commit history, we can still got to the target commit git reflog will contain 30 days commit history…

rebase

rebase will redirect base of current commit to target

$ git rebase dog
First, rewinding head to replay your work on top of it...
Applying: add cat 1
Applying: add cat 2

  • cancel rebase
    1. use reflog to reset back
    2. use ORIG_HEAD
      $ git reset ORIG_HEAD --hard