1

At an interactive prompt, I can use the git branch -r --no-merged command to determine remote branches that haven't been merged yet. However, git branch is a porcelain command and therefore is not suitable for use in a script.

Is there any good plumbing command I can use to determine the same branches returned by the --no-merged option?

user2221343
  • 614
  • 5
  • 16
  • [This post](http://stackoverflow.com/questions/15589862/git-find-all-unmerged-commits-in-master-grouped-by-the-branches-they-were-create) has some suggestions around parsing this information. Maybe you can find something there? – jas_raj Feb 16 '15 at 16:57

1 Answers1

3

I found that the command git merge-base supports an --is-ancestor argument to check if a commit is contained in the history of another. Using this, I can find unmerged remote refs like this (in ksh):

function showUnmerged {
    typeset -a unmergedRefs=()

    git for-each-ref --format='%(objectname) %(refname)' refs/remotes | \
    while read -r hash ref; do
        git merge-base --is-ancestor "$hash" "$1" || unmergedRefs+=("$ref")
    done

    echo "${unmergedRefs[@]}"
}

showUnmerged HEAD

This doesn't seem to be particularly efficient, but it does work and as far as I know, both for-each-ref and merge-base are plumbing commands

user2221343
  • 614
  • 5
  • 16