Skip to content

Instantly share code, notes, and snippets.

@grauwoelfchen
Created June 23, 2013 18:01
Show Gist options
  • Save grauwoelfchen/5845924 to your computer and use it in GitHub Desktop.
Save grauwoelfchen/5845924 to your computer and use it in GitHub Desktop.
Displays behind/ahead like GitHub's Branches view :)
function st-branch() {
local branch remote ahead behind
if [[ -n $1 ]]; then
remote=$1
else
remote="upstrm"
fi
git for-each-ref --format="%(refname:short)" refs/heads refs/remotes | \
while read branch
do
ahead=`git rev-list remotes/"${remote}"/master..${branch} --count 2>/dev/null`
behind=`git rev-list ${branch}..remotes/"${remote}"/master --count 2>/dev/null`
printf "%-30s %16s | %-15s %s\n" "$branch" "(behind $behind)" "(ahead $ahead)" "remotes/${remote}/master"
done
}
@grauwoelfchen
Copy link
Author

% st-branch upstrm
master                               (behind 5) | (ahead 1)       remotes/upstrm/master
stumpish-notifier                    (behind 5) | (ahead 1)       remotes/upstrm/master
origin/HEAD                          (behind 5) | (ahead 0)       remotes/upstrm/master
origin/master                        (behind 5) | (ahead 0)       remotes/upstrm/master
origin/stumpish-notifier             (behind 5) | (ahead 1)       remotes/upstrm/master
origin/v2.0                         (behind 21) | (ahead 1)       remotes/upstrm/master
origin/v2.0_refactorings            (behind 21) | (ahead 35)      remotes/upstrm/master
upstrm/gh-pages                   (behind 1524) | (ahead 3)       remotes/upstrm/master
upstrm/master                        (behind 0) | (ahead 0)       remotes/upstrm/master
upstrm/v2.0                         (behind 21) | (ahead 1)       remotes/upstrm/master
upstrm/v2.0_refactorings            (behind 21) | (ahead 46)      remotes/upstrm/master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment