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 1.1k times
14
-
4Possible 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
3 Answers
18
git branch --contains <branch>
will print all local branches where the commit labelled by <branch>
is an ancestor.

SzG
- 12,333
- 4
- 28
- 41
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
- 128,036
- 21
- 144
- 167
1
You can use gitg for this. See also visual editor.

Dan Lowe
- 51,713
- 20
- 123
- 112

Oleg Borodko
- 106
- 1
- 10