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?

  • New to git — how do I get changes from cloned repo into original repo?
  • Squash feature branch commit after merging from master
  • What's the difference between 'git fetch' and 'git fetch --all'
  • Version controlling super/sub projects using git
  • Version control for large binary files and >1TB repositories?
  • Version Control for Visual Studio projects and MS Dynamics CRM (javascript)
  • Copy a git-push to another computer, or perform smaller incremental pushes?
  • What to do when a patch for Mercurial import fails?
  • One Solution collect form web for “Git: get the list of branches into which current branch was ever merged”

    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.
    Git Baby is a git and github fan, let's start git clone.