Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Forked from jehiah/git-branch-status
Last active December 10, 2015 18:48
Show Gist options
  • Save zeroeth/4476648 to your computer and use it in GitHub Desktop.
Save zeroeth/4476648 to your computer and use it in GitHub Desktop.
#!/bin/bash
# modified from https://gist.github.com/1288596 by http://github.com/jehiah
# JAN 01 2013 by http://github.com/zeroeth
#
# Show distance between local master and remote branches
# list how far apart from local master each branch is
echo "Distance from master:"
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
do
git rev-list --left-right ${local}...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)
echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) master"
done
# also list how far out of sync locals are with their remotes
echo ""
echo "Distance from own remote:"
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 "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment