Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get branch divergence information on arbitrary refs in git

Tags:

git

I'm trying to create some statistics on potentially abandoned branches in our project.

For that I would love to compare each branch with the main branch and print how many commits it is ahead/behind main. - What is the correct command to get this kind of information?

A bad workaround is creating a temporary local branch, setting main as upstream and have a look at git branch -vv, which will show something like: tmp 82382e7 [origin/main: ahead 2, behind 10].

Is there a single command to get the "ahead 2, behind 10" without the need of a temporary local branch?

like image 208
michas Avatar asked Oct 29 '25 07:10

michas


1 Answers

Ok, I found it myself:

git rev-list --left-right --count ref1...ref2
like image 176
michas Avatar answered Oct 31 '25 21:10

michas