Skip to content

Instantly share code, notes, and snippets.

@pcapriotti
Created July 31, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcapriotti/3217608 to your computer and use it in GitHub Desktop.
Save pcapriotti/3217608 to your computer and use it in GitHub Desktop.
summary of branches
#!/bin/bash
# based on https://gist.github.com/1288596
RED="\033[0;31m"
YELLOW="\033[0;33m"
GREEN="\033[0;32m"
NOCOLOR="\033[00m"
BOLD="\033[1;37m"
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
do
[ -z "$remote" ] && remote="master"
git rev-list --left-right ${local}...${remote} -- 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)
BRANCH_NAME=$(echo -e "$local:" | sed -e :a -e 's/^.\{1,20\}$/& /;ta')
echo -ne "${BOLD}${BRANCH_NAME}${NOCOLOR}"
if [ "$LEFT_AHEAD" -gt 0 ]; then
if [ "$RIGHT_AHEAD" -gt 0 ]; then
STATUS="diverged ($LEFT_AHEAD ahead, $RIGHT_AHEAD behind)"
COLOR="$RED"
else
STATUS="ahead ($LEFT_AHEAD commits)"
COLOR="$GREEN"
fi
elif [ "$RIGHT_AHEAD" -gt 0 ]; then
COLOR="$YELLOW"
STATUS="behind ($RIGHT_AHEAD commits)"
else
COLOR=""
STATUS="clean"
fi
STATUS=$(echo -e "$STATUS" | sed -e :a -e 's/^.\{1,36\}$/& /;ta')
echo -ne "${COLOR}${STATUS}${NOCOLOR}"
echo "from $remote"
rm -f /tmp/git_upstream_status_delta
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment