VB_
VB_

Reputation: 45722

Git: get the list of branches into which current branch was ever merged

Maybe each developer faced that uncomfortable moment when you don't remember whether you've merged you story code. So you looking for that code and find it's in my-feature branch. But you still don't remember whether you merged it or not.

Question: How to get a list of branches into which my-feature was merged?

Upvotes: 2

Views: 64

Answers (1)

jub0bs
jub0bs

Reputation: 66422

Have you tried the following command?

git branch -a --merged my-feature

It will print a list of all branches (local or remote) whose tips are reachable from (i.e. ancestors of) the tip of my-feature. If you're only interested in local branches only, you can want drop the -a option.

As an example, if your repository looks as follows

A -- B [branch1]
      \
       C -- D -- E [origin/HEAD=origin/branch2]
        \         \
         \         H -- I [HEAD=branch4]
          \
           F -- G [branch3]

Running

git branch -a --merged branch4

will print

* branch4
remotes/origin/HEAD -> origin/branch2
remotes/origin/branch2
branch1
  • Why branch4? Because branch4 is trivially reachable from itself.
  • Why remotes/origin/HEAD and remotes/origin/branch2? Because they both point (indirectly and directly, respectively) to commit E, which is an ancestor of branch4's tip, commit I.
  • Why branch1? Because it points to commit B, which is an ancestor of commit I.
  • Why not branch3? Because it points to commit G, which is not an ancestor of commit I.

Upvotes: 2

Related Questions