Home > Blockchain >  Git fetch does not fetch the latest commits from the remote
Git fetch does not fetch the latest commits from the remote

Time:07-05

I have a two-machine (Mac and Win) setup where I need to transfer changes from the Windows machine to the Mac. So I make my changes on the Win machine, commit and push them to GitHub. So far, so good. (I have confirmed that the new commits are indeed on GitHub.)

But I have recently started having a problem on the Mac that git fetch origin does not fetch the new commits from GitHub. Therefore git pull (with the branch in question checked out) tells me it is already up to date.

This repository is a submodule. I looked at the config files for the submodule on both machines, which have identical settings for remotes and for the branch. They look as follows (with account and branch names changed to generic ones).

[remote "origin"]
    url = [email protected]:upstream/myrepo.git
    fetch =  refs/heads/*:refs/remotes/origin/*
    pushurl = [email protected]:personal/myrepo.git
[remote "upstream"]
    url = [email protected]:upstream/myrepo.git
    fetch =  refs/heads/*:refs/remotes/upstream/*

[branch "mybranch-name"]
    remote = origin
    merge = refs/heads/mybranch-name

My question is, does anyone know why git fetch origin from the Mac is ignoring the new commits in the remote repository? Is there a way to force it to fetch from the actual remote repository on GitHub? (Since clearly this is not currently happening.)

Currently I have partial write access to the upstream remote, which allows me to work around this problem by pushing my branch there, then pulling it into the local branch on the Mac (then pushing to origin from the Mac). But I will soon be losing write access to upstream.

If it matters, I normally use SourceTree to manage git, but in this case I have been doing the git commands directly from the command line with no difference in behavior. I have several other submodules that are not having this problem, nor is the main repository.

CodePudding user response:

The separate url and pushurl here are suspicious:

[remote "origin"]
    url = [email protected]:upstream/myrepo.git
    fetch =  refs/heads/*:refs/remotes/origin/*
    pushurl = [email protected]:personal/myrepo.git

As the git remote documentation says:

Note that the push URL and the fetch URL, even though they can be set differently, must still refer to the same place. What you pushed to the push URL should be what you would see if you immediately fetched from the fetch URL. If you are trying to fetch from one place (e.g. your upstream) and push to another (e.g. your publishing repository), use two separate remotes.

This caveat is, unfortunately, apparently only found in the git remote documentation; it probably should be in git fetch, git push, and git config documentation as well.

(As you've confirmed in the comments, this seems to be the basic problem, and apparently SourceTree did this for some reason known only to SourceTree.)

  • Related