Skip to content

Instantly share code, notes, and snippets.

@courtney-miles
Created May 17, 2018 23:46
Show Gist options
  • Save courtney-miles/2ac3f95cc1609b186c13d3493f1745a1 to your computer and use it in GitHub Desktop.
Save courtney-miles/2ac3f95cc1609b186c13d3493f1745a1 to your computer and use it in GitHub Desktop.
Prints the ahead and behind status for each tracked branch.
#!/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