-
-
Save fredrikhl/0ca1b558dc35e972c64f to your computer and use it in GitHub Desktop.
git branch-status command
This file contains 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 | |
# | |
# 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