Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
show git ahead/behind info for branches
#!/bin/bash
# forked from http://github.com/jehiah
# this prints out some branch status (similar to the '... ahead' info you get from git status)
# example:
# $ git branch-status
# dns_check (ahead 1) | (behind 112) origin/master
# master (ahead 2) | (behind 0) origin/master
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
do
[ -z "$remote" ] && continue
DELTAS=$(git rev-list --left-right ${local}...${remote})
LEFT_AHEAD=$(echo "$DELTAS" | grep -c '^<')
RIGHT_AHEAD=$(echo "$DELTAS" | grep -c '^>')
echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.