3

I'm trying to build a reliable "repo ahead and behind" signal for my bash prompt. Despite reading source code for many git prompts (shell, python scripts) and reading many stack overflow answers, I could not figure out why comparing

$ git rev-list HEAD..origin/master

did not actually compare master at the origin. Figured it out, so I decided to ask this question and answer it so it's not buried and will immediately answer someone else's similar question.

Terence Parr
  • 5,912
  • 26
  • 32

1 Answers1

2

It finally dawned on me that origin/master is just a local "pointer", which makes sense with git's distributed nature. It really threw me until I remembered this. Almost none of the answers about comparing local and remote repos comes right out and says that you must do a fetch. Finally found one. Anyway, I have parrt's git bash prompt working in a very reliable way. To determine whether your repository is behind the origin, do this:

$ git fetch origin mybranch
$ git rev-list HEAD..origin/mybranch

This is expensive so my bash prompt script does it every 30 minutes to see if I'm behind remote repo.

Community
  • 1
  • 1
Terence Parr
  • 5,912
  • 26
  • 32