Created
November 19, 2015 13:38
-
-
Save mhafalir/28753aa2cbd260f708ff to your computer and use it in GitHub Desktop.
git branch status
This file contains hidden or 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
#!/bin/bash | |
# by 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 | |
COLOR_RED="\033[0;31m" | |
COLOR_YELLOW="\033[0;33m" | |
COLOR_GREEN="\033[0;32m" | |
COLOR_OCHRE="\033[38;5;95m" | |
COLOR_BLUE="\033[0;35m" | |
COLOR_WHITE="\033[0;37m" | |
COLOR_RESET="\033[0m" | |
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \ | |
while read local remote | |
do | |
[ -z "$remote" ] && continue | |
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) | |
printf "$COLOR_GREEN %-30s" "$local" | |
if [ "$LEFT_AHEAD" -gt 0 ];then | |
printf "$COLOR_BLUE %-12s" "(ahead $LEFT_AHEAD)" | |
else | |
printf "$COLOR_RESET %-12s" "(ahead $LEFT_AHEAD)" | |
fi; | |
if [ "$RIGHT_AHEAD" -gt 0 ];then | |
printf "$COLOR_RED %-12s $COLOR_RESET $remote\n" "(behind $RIGHT_AHEAD)"; | |
else | |
printf "$COLOR_RESET %-12s $COLOR_RESET $remote\n" "(behind $RIGHT_AHEAD)"; | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+rep