I just observed something odd about git pull
, which I don't understand.
On Friday, I worked on a local branch. let's call it mybranch
. Before leaving the office I pushed it to origin (which is my github repo): git push origin mybranch
.
Yesterday at home, I pull
ed mybranch to my laptop, did some more coding, and then pushed my changes back to github (origin).
Now I'm at work again, and tried to pull the changes from yesterday to my work machine (I didn't change anything in my work place's local repo over the weekend):
git pull origin mybranch
that caused a fast forward merge, which is fine. I then did a git status
, and it said:
# On branch mybranch
# Your branch is ahead of 'origin/mybranch' by 6 commits.
#
nothing to commit (working directory clean)
Huh? How can it be 6 commits ahead when I didn't even touch it over the weekend, AND just pulled from origin? So I ran a git diff origin/mybranch
and the diffs were exactly the 6 changes I just pulled from remote.
I could only "fix" this by running git fetch origin
:
From [email protected]:me/project
af8be00..88b0738 mybranch -> origin/mybranch
Apparently, my local repo was missing some reference objects, but how can that be? I mean, a pull does a fetch already, and I didn't work on anything except that branch, so a git fetch origin
and git fetch origin mybranch
should have the same result?
Should I always use git pull origin
instead of git pull origin branchname
?
I'm confused.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…