DustinZhang DustinZhang - 29 days ago 8
Git Question

git fetch does not update .git/refs/remotes/origin/master

I have a local git repository cloned from a central server. The last commit of my local master branch is commit 1.

The central repository has a new commit 2 in master branch.

I ran

git fetch origin master
to update my local refs, I found
does not update.

And then I checked
. This is, however, already commit 2

My local config for the fetch:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = #########

Also I am able to login to central and check the bare repository there.
is commit 2

Then I tried to run
git pull origin master
. Surprisingly, commit 2 is merged into my local repository.

git diff origin/master
even shows me the diffs between commit 1 and commit 2. But origin and my local repository have the same contents at this point.

My questions are:

  1. Why
    git fetch
    does not download the latest update from origin?

  2. Why
    git pull
    still works in this case?

  3. Is it a problem of my local config or the central config?

Answer Source

If you run

git fetch origin

then refs/remotes/origin/master will be updated.

If you specify a single ref to git fetch origin, then it assumes you just want to pull that to FETCH_HEAD

you can run

git fetch origin master:refs/remotes/origin/master

and that will also update