5

Our teams tend to not keep track of how many commits they are behind the latest released code. We want to notify them of that, but getting the information is the hard part, the notify part is done.

What I would like to understand how to pull the git log down, do a git command that outputs "Branch x is behind branch y by 5 commits". I don't want to have to checkout the branch as it pulls down our 600mb+ repo each time for all of our branches, plus I'm running low on drive space. I have found similar questions on stack overflow that reference bash scripts that only work locally, or the ones that point to remote return blank. I'm still learning git and bash, please bear with me.

Josh
  • 2,248
  • 2
  • 19
  • 38

1 Answers1

11

What you need is git rev-list (reverse chronological order of commits).

After cloning a repo (make sure the remote is set and git fetch origin has been performed), to get ahead number of the branch from master, try

git rev-list origin/master..origin/feature/SuperCoolBranch --count

switch the branches around to find out the behind number.

Sai Puli
  • 951
  • 8
  • 12
  • 4
    This should work with current branch, should it? `git rev-list HEAD..origin --count` – Liero Sep 21 '17 at 15:46
  • Yes, what you mentioned should work on current branch. – Sai Puli Sep 29 '17 at 13:42
  • 2
    Is there really no way to do this without having to actually retrieve the entire remote branch? – Neutrino Nov 04 '17 at 23:26
  • @Neutrino, no there is not. Git doesn't store metadata, so queries require consideration of all the historical commits in question, and there is no existing built in mechanism to query this information on a remote repository. – bschlueter Nov 29 '22 at 21:33