Skip to content

Instantly share code, notes, and snippets.

@kd35a
Forked from jehiah/git-branch-status
Last active October 18, 2022 14:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kd35a/7924799 to your computer and use it in GitHub Desktop.
Save kd35a/7924799 to your computer and use it in GitHub Desktop.
#!/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
tot_diff=0
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)
tot_diff=$LEFT_AHEAD+$RIGHT_AHEAD+$tot_diff
echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote"
done
if [ "$tot_diff" == "0" ]; then
echo "Everything is synchronized."
fi
@bill-auger
Copy link

building on @knovoselic version - i prettified it a bit more:

  • formatted results into columns
  • added ability to filter by branch name and to show locals
  • removed the temp file i/o
  • added some switches and usage message

https://gist.github.com/bill-auger/9335fe2633eae38d3070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment