Skip to content

Instantly share code, notes, and snippets.

@fredrikhl
Forked from jehiah/git-branch-status
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrikhl/0ca1b558dc35e972c64f to your computer and use it in GitHub Desktop.
Save fredrikhl/0ca1b558dc35e972c64f to your computer and use it in GitHub Desktop.
git branch-status command
#!/bin/bash
#
# From: http://github.com/jehiah
#
# Usage: Run `git-branch-status.sh' in a git repository
# OR `git branch-status' if the script is in your ${PATH}
#
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
local_ahead=$( grep -c '^<' /tmp/git_upstream_status_delta )
local_behind=$( grep -c '^>' /tmp/git_upstream_status_delta )
printf "%2d+ %2d- %s -> %s\n" \
"${local_ahead}" "${local_behind}" "$local" "$remote"
done
#
# If your version has the `--count'-option for `git rev-list', you could remove
# the `git rev-list' line and just do:
# local_ahead=$( git rev-list ${local}...${remote} --count )
# local_behind=$( git rev-list ${remote}...${local} --count )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment