Checking Git Merge Status

Categories: Programming, Git

One of the software applications I work on uses Git as version-control and has a traditional (if somewhat old-fashioned) branching strategy: a branch per feature/bugfix, an integration branch, a release-testing branch, and release branches. Different users/tools are responsible for merging between these branches so it can sometimes be rather difficult to know whether a local Git branch has been merged to any specific target.

I put the following very simple script in ~/bin/isgitmerged:

HASH=`git rev-parse $SRC`
COMMON=`git merge-base $DST $SRC`
if [ "$COMMON" = "$HASH" ]; then
  echo "merged"
  echo "not merged"

Usage is simply:

  • git fetch --all
  • isgitmerged {targetbranch} {localbranch}

eg: isgitmerged origin/release/1234 bugfix/myfix