Skip to content

Instantly share code, notes, and snippets.

Last active May 4, 2023 02:47
What would you like to do?
show git ahead/behind info for branches
moved to github -->
Copy link

ghost commented Nov 29, 2012

try to run
git remote update
prior to running the script, this will sync your local repo to the remote one

Copy link

save having to parse the output...
instead of: git rev-list --left-right {local}...{remote}; use:
git rev-list {local}..{remote} --count
git rev-list {remote}..{local} --count

Copy link

hilbix commented Nov 29, 2013

Copy link

kd35a commented Dec 12, 2013

If anyone is interested, I've added a status-line at the end if everything is synchronized. Which is quite nice if you also have a morning routine of doing git fetch --all && git-branch-status.


Edit: I'm having problems with basic arithmetics in bash, what the? Well, don't use my code for the time being.

Copy link

tschulte commented Feb 7, 2014

git branch -v | grep -E 'ahead|behind' | sed -r 's/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\1 \2/g' does nearly the same. Using git branch -vv one could also get the upstream branch name.

Copy link

If anyone is interested, I've fixed kd35a's version of the script + added colors:

Copy link

if anyone interested - i found this script too - and i liked it - and i prettified it :)

building on @knovoselic version:

  • prettified into columns with adjustable max wdith
  • added ability to filter by branch name and to show locals
  • removed the temp file i/o - runs fully in memory
  • added command-line switches and usage message

my fork is here

Copy link

What a great script! 😍 Like you guys, I added colours and columns, and an indication of whether this branch has been merged into master, but I will admit my version is somewhat convoluted.

However, if you are only interested in the _current_ branch, then perhaps you would prefer to see ahead/behind counts on your prompt.

Git Branch in Prompt

Copy link

have add some features today

  • added '*' indicator near current branch
  • added dates of the last commit beside each branch and upstream

pull from my fork for the latest version

hopefully we can soon get this coordinated into a proper project

below is a screenshot of the latest version

alt text

Copy link

i have created a repo for this script on github in order to have a proper issue tracker - all further development and communications will take place there - feel free to clone, fork, star , or watch the github repo -->

this script is also now icluded in jwiegley's git-scripts collection but please direct comments, bug reports, and feature requests to the upstream issue tracker

@jehiah -
could you please merge my fork into yours - this will replace the script body with a link to the latest upstream repo on github like so:

git remote add bill-auger-gist
git fetch bill-auger-gist
git merge bill-auger-gist/master

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