Question

I'm having some trouble doing this in a non convoluted way... currently I can figure out which branches were merged into a branch by outputting branches --merged from the target branch and from master, writing the output from those commands to files, and then diffing those two files. Does anyone have a better way to get this info?

For example, say branches branch1, branch2, and branch3 are all cut from master and dev work is done on them. Then, branch1 and branch2 are merged into integrationBranch. The command should be able to tell me that branch1 and branch2 were merged into integrationBranch.

EDIT:

When I run git branch --merged, the branch that's merged in first is always dropped from the output.

Example:

git checkout inegraionBranch
git merge origin/branch1
git merge origin/branch2

git branch merged
*integrationBranch
branch2
Was it helpful?

Solution

In the case of your example you'll want to use git branch -a --merged integrationBranch

The two branches origin/branch1 and origin/branch2 are remote branches and aren't listed with git branch by default so neither is showing up in your output unless you use a -a switch.

I'm guessing the reason you are seeing branch2 is that you probably have a local branch named branch2 which is merged in (ie, the problem is not that the command is dropping the first branch)

EDIT:

To get all of the branches merged into integrationBranch but not into master you could do:

git branch --list -a --merged integrationBranch | sed 's/^..//;s/ .*//' | xargs git branch --list -a --no-merged master
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top