Created
January 26, 2014 21:42
-
-
Save vitalk/8639831 to your computer and use it in GitHub Desktop.
Show how many commits each branch is ahead or behind its upstream.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Usage: git-branch-status | |
# Show how many commits each branch is ahead or behind its upstream. | |
branch=`git rev-parse --abbrev-ref HEAD` | |
git for-each-ref --format='%(refname:short) %(upstream:short)' refs/heads | \ | |
while read local upstream; do | |
# Use master if upstream branch is empty | |
[ -z $upstream ] && upstream=master | |
ahead=`git rev-list ${upstream}..${local} --count` | |
behind=`git rev-list ${local}..${upstream} --count` | |
if [[ $local == $branch ]]; then | |
asterisk=* | |
else | |
asterisk=' ' | |
fi | |
# Show asterisk before current branch | |
echo -n "$asterisk $local" | |
# Does this branch is ahead or behind upstream branch? | |
if [[ $ahead -ne 0 && $behind -ne 0 ]]; then | |
echo -n " ($ahead ahead and $behind behind $upstream)" | |
elif [[ $ahead -ne 0 ]]; then | |
echo -n " ($ahead ahead $upstream)" | |
elif [[ $behind -ne 0 ]]; then | |
echo -n " ($behind behind $upstream)" | |
fi | |
# Newline | |
echo | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment