Search code examples
gitbranchgit-pushgit-pullgit-fetch

pull-only repo's 'git status' saying the branch is ahead of origin/master. Why?


So here's the situation:

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by [x] commits.
#

There are several questions about this on SO already, but none seem to specifically address the type of scenario I have. This answer to one of the questions comes closest, but doesn't go into detail.

I'll just quote it verbatim:

If you get this message after doing a "git pull remote branch", try following it up with a "git fetch".

Fetch seems to update the local representation of the remote branch, which doesn't necessarily happen when you do a "git pull remote branch".

That tip does indeed work. But "doesn't necessarily happen?" Why not? I need to understand this. What is pull not doing?

I don't want to take over that question, so here's my scenario in detail:

Three computers involved. The Mac on which I develop, my home server where the git repo (i.e. origin/master) lives and a Webfaction account that pulls from that server.

I do commits and git push origin master only on the Mac. The only command that ever gets run on Webfaction as part of the normal workflow is git pull origin master (as part of a Fabric deployment script). I don't modify code there. I'm a lone developer, so neither does anyone else.

Every now and then I log in to Webfaction and check on things, including a git status. Inevitably, I always get the "Your branch is ahead..." message. Running git fetch makes the message go away.

I'm about to add git fetch to the Fabric script to be done with this issue, but I want to know why that needs to be done, especially on a pull-only clone of origin/master. I'm not deeply versed in Git though I use the basic functionality daily, so a newbie-friendly explanation would be appreciated.

Update as requested, the relevant bits from config:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@[server_address]:[path/to/repo.git]
[branch "master"]
    remote = origin
    merge = refs/heads/master

Solution

  • Note: this question was recently linked-to from Git: unable to get remote and local/server the same. Note that the date on the original question is September 2011; the then-most-current version of Git was 1.7.10. Git is now at version 2.26.2.

    In versions of Git predating Git 1.8.4, running git pull origin master suppresses updating the local name origin/master. (So does running git fetch origin master.)

    Running git fetch, with no additional arguments, causes all versions of Git—before and after 1.8.4—to update all remote-tracking names, including origin/master. So that's the real explanation behind this mystery.