Skip to content

Instantly share code, notes, and snippets.

@joshrp
Last active January 2, 2016 02:19
Show Gist options
  • Save joshrp/8236604 to your computer and use it in GitHub Desktop.
Save joshrp/8236604 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
# check branches created from and merged to this branch
REMOTE=upstream
COMPAREBRANCH=develop
MASTER=refs/remotes/$REMOTE/$COMPAREBRANCH
git fetch $REMOTE
# for each remote branch...
for BRANCH in $(git for-each-ref --format='%(refname)' refs/heads/); do
# ...except the $MASTER branch and the current HEAD
[[ $BRANCH == $MASTER || $BRANCH =~ /HEAD$ ]] && continue
# get the hash for the head of the branch
BRANCH_HEAD=$(git show-ref --head --hash $BRANCH)
# returns the first shared commit among $MASTER and $BRANCH commits
BRANCH_POINT=$(fgrep -m 1 -f <(git rev-list --first-parent $BRANCH) \
<(git rev-list --first-parent $MASTER))
# find the best merge point
BRANCH_MERGE=$(git merge-base $MASTER $BRANCH)
# determine the type of branch
if [[ $BRANCH_POINT == $BRANCH_HEAD ]]; then
echo -e "$BRANCH: \t\t\tnew branch with 0 commits"
elif [[ $BRANCH_MERGE == $BRANCH_HEAD ]]; then
echo -e "$BRANCH: \t\tfully merged into $REMOTE/$COMPAREBRANCH"
else
echo -e "$BRANCH: \t\tbranch with changes"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment