Git Branch Management - Viewing Branches
# Git Branch Management - Viewing Branches
# Viewing Branches
$ git branch
iss53
* master # The asterisk * indicates the current branch
testing
2
3
4
The git branch command does more than just create and delete branches. When run without arguments, it lists all current branches.
# Viewing the Last Commit on Each Branch
$ git branch -v
iss53 93b412c fix javascript issue
* master 7a98805 Merge branch 'iss53'
testing 782fd34 test
2
3
4
# Viewing Merged / Unmerged Branches
The --merged and --no-merged options let you see which branches have or have not been merged into the current branch.
$ git branch --merged # List merged branches
iss53
* master
2
3
Branches in this list without the * prefix can generally be deleted with git branch -d;
$ git branch --no-merged # List unmerged branches
testing
2
The above shows the unmerged branch. Attempting to delete it with git branch -d will fail:
$ 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'.
2
3
Force delete an unmerged branch:
$ git branch -D testing
# Viewing Merged / Unmerged Branches for a Specific Branch
The --merged and --no-merged options described above will, if no commit or branch name is given as an argument, list branches that have or have not been merged into the current branch.
You can always provide an additional argument to check the merge status of other branches without checking them out. For example, which branches have not been merged into the testing branch?
$ git branch --no-merged testing
topicA
featureB
2
3