In command line, how can I check whether a branch has been merged into another branch, and if yes, find out which branch it has been merged into?
Asked
Active
Viewed 9,451 times
11
-
2Possible duplicate of [How can I know in git if a branch has been already merged into master?](http://stackoverflow.com/questions/226976/how-can-i-know-in-git-if-a-branch-has-been-already-merged-into-master) – CodeCaster Mar 16 '17 at 19:47
-
Try `git diff master...` (and replace `master` with whatever "target" branch you want to check). If this returns `nil` then there are no changes that exist in your current branch that are not in your "target" branch. _(As always, triple check before deleting the branch and always make sure you have good backups.)_ – Joshua Pinter Oct 03 '21 at 16:34
4 Answers
16
git branch --contains <branch>
will print all local branches where the commit labelled by <branch> is an ancestor.
SzG
- 11,777
- 4
- 25
- 38
5
With
--contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit)
--contains[]
Only list branches which contain the specified commit (HEAD if not specified)
git branch --contains <commit/tag/branch>
Community
- 1
- 1
CodeWizard
- 110,388
- 20
- 126
- 153
1
You can use gitg for this. See also visual editor.
Dan Lowe
- 44,653
- 17
- 114
- 109
Oleg Borodko
- 108
- 1
- 10
-1
if your do something like
git checkout a
git merge b
you will merge b into a
when your merge you are creating a merge commit so you should be able to see the commit in
git log
leurer
- 303
- 2
- 9
-
2right but sometimes you want to check, without actually attempting a merge – Alexander Mills Nov 24 '17 at 23:11
-
3