Created
May 17, 2018 23:46
-
-
Save courtney-miles/2ac3f95cc1609b186c13d3493f1745a1 to your computer and use it in GitHub Desktop.
Prints the ahead and behind status for each tracked branch.
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 | |
# Adapted from https://stackoverflow.com/a/7774433/2045006 | |
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) | |
echo -e "\033[32m$local\033[00m...\033[31m$remote\033[00m [ahead \033[32m$LEFT_AHEAD\033[00m] [behind \033[31m$RIGHT_AHEAD\033[00m]" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment