Skip to content

Instantly share code, notes, and snippets.

@lth2h
Forked from jehiah/git-branch-status
Created November 30, 2012 18:20
Show Gist options
  • Save lth2h/4177524 to your computer and use it in GitHub Desktop.
Save lth2h/4177524 to your computer and use it in GitHub Desktop.
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