2

I understand that if I have commits on my local master branch that are not in the remote master branch, then I can get "Your branch is ahead of origin/master by X commits".

But, after I git pull origin master, I see the message "Already up-to-date". So, I thought that means exactly that: none of my commits are ahead/behind master.

But when I do git status still am receiving this message "Your branch is ahead of origin/master by X commits". Even when I do git pull -f origin master I'm still getting this message!! How is that possible when I'm "Already up-to-date"?

I understand questions like this, but they still don't tell me why the "up-to-date" means "ahead"?

Community
  • 1
  • 1
makansij
  • 9,303
  • 37
  • 105
  • 183

1 Answers1

2

Let’s illustrate by below graphs:

Assume this is the remote master branch,

A---B---C origin/master

And this is your local master branch, you make X commits on local,

A---B---C---D---E---…---N master

So when you want to pull remote master branch(commit A,B and C) to local which already exist in local commits, so git will show already up-to-date message for you. And this is consistent with git status’ messge Your branch is ahead of origin/master by X commits.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • Okay, so "ahead" just means ahead chronologically in terms of commits? – makansij Jan 05 '17 at 05:12
  • Yes, ahead means the commits X which you added locally. – Marina Liu Jan 05 '17 at 05:15
  • @Candic3: think of it not so much "chronologically" as "topologically", because it's not *time*-based but *location*-based. You are ahead because *you* are ahead. If I also wrote back to the shared repository on your `origin` and *I* got ahead of that `origin` and then *I* pushed to it and *got there first*, I would have my commits on `origin` (they would now be ahead of you by *my* commits) and you would have your commits not yet on `origin` (so you are *also* ahead of `origin`). But if I win this push "race", it's now up to you to collect those commits and figure out how to integrate them. – torek Jan 05 '17 at 07:22