Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to find all branches that were never merged back into master

We have a fairly large GIT repo and I would like to remove branches that were never merged back into master.

The reverse is fine too - a way to list all branches that have been merged into master at some point.

I would like a get a list to begin with rather then simply deleting the branches right away, since some branches may be worth keeping still or have been in development more recently.

So the question is: Is there a way to list all branches that never had any of their changes merged back into master?

like image 697
ideasman42 Avatar asked Oct 29 '13 06:10

ideasman42


2 Answers

git branch --no-merged master

Or for the other way, git branch --merged master

docs

like image 127
Eevee Avatar answered Sep 18 '22 18:09

Eevee


git help branch says:

   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). With --merged, only branches merged into the named
   commit (i.e. the branches whose tip commits are reachable from the
   named commit) will be listed. With --no-merged only branches not merged
   into the named commit will be listed. If the <commit> argument is
   missing it defaults to HEAD (i.e. the tip of the current branch).

Hence, for finding all branches already merged to master you can use git branch --merged master.

like image 42
michas Avatar answered Sep 16 '22 18:09

michas