Skip to content

Instantly share code, notes, and snippets.

@kevinawoo
Forked from jehiah/git-branch-status
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save kevinawoo/10787387 to your computer and use it in GitHub Desktop.

Select an option

Save kevinawoo/10787387 to your computer and use it in GitHub Desktop.
#!/bin/bash
# git functions
__git_branch_info() {
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 -n "$local..$remote,"
[ $LEFT_AHEAD != 0 ] && echo -n "[ahead $LEFT_AHEAD]"
[ $RIGHT_AHEAD != 0 ] && echo -n "[behind $RIGHT_AHEAD]"
echo
done
}
output=$(__git_branch_info | column -t -s '..')
output=${output//[" "] /".."}
output=${output//[". "] /".."}
echo "$output" | column -t -s ','
statuses = "!f() { __git_alias_statuses; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment