Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active December 31, 2015 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeroeth/8013177 to your computer and use it in GitHub Desktop.
Save zeroeth/8013177 to your computer and use it in GitHub Desktop.
git branch distance status
#!/bin/bash
# modified by http://github.com/zeroeth for color/alignment
# modified by http://github.com/kortina
# original from http://github.com/jehiah
# this prints out branch ahead/behind status vs origin/master for all branches
# 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/ | \
while read local remote
do
if [ -x $remote ]; then
branches=("$local")
else
branches=("$local" "$remote")
fi;
for branch in ${branches[@]}; do
master="master"
git rev-list --left-right ${branch}...${master} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
LEFT_AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
RIGHT_AHEAD=$(grep -c '^>' /tmp/git_upstream_status_delta)
COLOR="MEOW"
if [ "$LEFT_AHEAD" -eq "0" ]; then
if [ "$RIGHT_AHEAD" -eq "0" ]; then
# NOTHING NEW AND EQUAL
COLOR="\033[0;35m⚡"
else
# NOTHING NEW AND BEHIND
COLOR="\033[0;33m↓"
fi;
else
if [ "$RIGHT_AHEAD" -eq "0" ]; then
# NEW AND UP TO DATE
COLOR="\033[0;32m↑"
else
# NEW AND BEHIND
COLOR="\033[0;31m↕"
fi;
fi;
printf "$COLOR %-30s (ahead %2d) | (behind %4d) $master\n" $branch $LEFT_AHEAD $RIGHT_AHEAD
done
done | grep -v "^master" | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment