Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias that displays how many commits branches are ahead/behind master

Tags:

git

The new Bitbucket Branches page is awesome. It shows how many commits each branch is ahead/behind master. Is there an Git alias that displays same information?

The information should display:

  • Branch name
  • When it was updated last
  • How many commits its behind master
  • How many commits its ahead of master

http://i.imgur.com/VsOH4cr.png

like image 507
Gaui Avatar asked Dec 28 '25 01:12

Gaui


2 Answers

Take a look at the script I posted in an answer to a slightly different question: https://stackoverflow.com/a/18760795/683080

You need to make sure you're up-to-date with a git fetch or git fetch --all. And once you are, you can use it to display how far ahead or behind the branches are. Git doesn't store cached versions of this information, so if you're branch is really far behind (like 6,000 commits behind the current tip of the Linux kernel), then it may take a little while to compute. Otherwise, it's pretty quick.

One small note: the script doesn't show the date it was last updated, but it does show the rest.

like image 60
John Szakmeister Avatar answered Dec 31 '25 00:12

John Szakmeister


If you setup 'master' as the upstream tracking branch:

git branch --set-upstream-to master

And then do git branch -vv, should see how many commits your topic branch is ahead/behind. As for the last time a branch got updated, I don't think Git stores such information.

like image 27
FelipeC Avatar answered Dec 30 '25 23:12

FelipeC