3

When I do git fetch, nothing happens, even though I can see that my origin/master is behind the one on GitHub. The only output I get from git fetch is

$ git fetch origin
From github.com:myname/myrepo
 * branch            master      -> FETCH_HEAD

The output I want is

$ git fetch
From github.com:myname/myrepo
   6a6a103..77edb9d  master     -> origin/master
 * [new branch]      feature    -> origin/feature

when I run git ls-remote:

$ git ls-remote
From git@github.com:myname/myrepo.git
77edb9d40be3a75bd25288ab375ef16e009267fa        HEAD
77edb9d40be3a75bd25288ab375ef16e009267fa        refs/heads/master      <-- latest
9f2c06129eefef3f1cdc96499058d7b58e2ad0b6        refs/heads/feature

but git show-ref gives me

$ git show-ref
e4d894a2db19c3dbbdb946b25142c981695e0790 refs/heads/master
9f2c06129eefef3f1cdc96499058d7b58e2ad0b6 refs/heads/feature
6a6a10322110a690044e267eb7644613057dd932 refs/remotes/origin/master    <-- old!

Why won't git fetch do anything?

Dan
  • 12,409
  • 3
  • 50
  • 87

2 Answers2

4

If there is a way to fix this via the command line?

You can use a git config command (to fetch again all remote branches):

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

origin's refspec is hosed. The refspec is the part of the remote configuration that tells git what to fetch and how. It is described in more detail here.

In .git/config there is a section

[remote "origin"]
    url = git@github.com:myname/myrepo.git

This should look like

[remote "origin"]
    url = git@github.com:myname/myrepo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

If there is a way to fix this via the command line, I am not aware of it. I also do not know why this happened.

Dan
  • 12,409
  • 3
  • 50
  • 87