Skip to content

Instantly share code, notes, and snippets.

@jehiah
Last active March 21, 2024 12:39
Show Gist options
  • Star 56 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save jehiah/1288596 to your computer and use it in GitHub Desktop.
Save jehiah/1288596 to your computer and use it in GitHub Desktop.
show git ahead/behind info for branches
moved to github --> https://github.com/bill-auger/git-branch-status/
@bergerjac
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

@hilbix
Copy link

hilbix commented Nov 29, 2013

@kd35a
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.

See: https://gist.github.com/kd35a/7924799

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

@tschulte
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.

@knovoselic
Copy link

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

https://gist.github.com/knovoselic/1a20dc28dbb0141fc176

@bill-auger
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

@joeytwiddle
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

@bill-auger
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

@bill-auger
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 -->

https://github.com/bill-auger/git-branch-status/

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 https://gist.github.com/9335fe2633eae38d3070.git
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