Skip to content
Created: November 18, 2017

Git branch management-view branches ​

View branches ​

sh
$ git branch
  iss53
* master  # 带星号*表示当前所在分支
  testing

The git branch command can not only create and delete branches.If you run it without any parameters, you will get a list of all current branches.

View the last commit of each branch ​

sh
$ git branch -v
  iss53   93b412c fix javascript issue
* master  7a98805 Merge branch 'iss53'
  testing 782fd34 test

View merged branches ​

--merged and --no-merged are two options to see which branches have been merged or not merged into the current branch.

sh
$ git branch --merged # 查看已合并分支列表
  iss53
* master

Branches in the above list without * before the branch name can usually be deleted using git branch -d;

sh
$ git branch --no-merged # 查看未合并的分支列表
  testing

The above shows an unmerged branch, and trying to delete it using the git branch -d command fails:

sh
$ git branch -d testing
error: The branch 'testing' is not fully merged.
If you are sure you want to delete it, run 'git branch -D testing'.

Force deletion of unmerged branches:

sh
$ git branch -D testing

View the (un)merged branches of the specified branch ​

Options described above --merged and --no-merged Will list merged or unmerged into respectively when no commit or branch name is given as argument. current Branches of branches.

You can always provide an additional argument to see the merge status of other branches without having to check them out.For example, what hasn't been merged into the testing branch yet?

sh
$ git branch --no-merged testing
  topicA
  featureB