1

My .git/config file in my git repo already contains below setting:

[remote "origin"]
    url = //URL to remote repo
    fetch = +refs/heads/*:refs/remote/origin/*

Still when I try git fetch in my git bash, it returns nothing.

But if I run git config remote.origin.fetch "+refs/heads/*:refs/remote/origin/*" in my git bash before doing git fetch, it list all the required remote branches details.

Why do I have to set it every time before doing git fetch? Is there any way I don't have to do that every time I do a git fetch?

  • You *don't* have to set it every time. Something else must be going on, tricking you into thinking that you do. Posting exact commands and their results might help diagnose the real issue, whatever it is. – torek Jul 04 '18 at 16:24
  • Does `git fetch origin` work as you expect? – jwir3 Jul 04 '18 at 16:50
  • Does my post below answer your question? – VonC Jul 09 '18 at 06:39

1 Answers1

0

I just tested it on a local clone of the Git repo (https://github.com/git/git/)

The first fetch does return nothing

vonc@voncvb C:\Users\vonc\prog\git\git
> git fetch

The config is already set to the default value:

vonc@voncvb C:\Users\vonc\prog\git\git
> git config remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*

If I set again the config, and do a git fetch, I do see indeed additional information:

vonc@voncvb C:\Users\vonc\prog\git\git
> git config remote.origin.fetch "+refs/heads/*:refs/remote/origin/*"

vonc@voncvb C:\Users\vonc\prog\git\git
> git fetch
From https://github.com/git/git
 * [new branch]            master     -> refs/remote/origin/master
 * [new branch]            maint      -> refs/remote/origin/maint
 * [new branch]            next       -> refs/remote/origin/next
 * [new branch]            pu         -> refs/remote/origin/pu
 * [new branch]            todo       -> refs/remote/origin/todo

But if I repeat the git config command again (git config remote.origin.fetch "+refs/heads/*:refs/remote/origin/*") and do additional git fetch, they won't return any new information (empty output)

That is because the first one completed the FETCH_HEAD:

vonc@voncvb C:\Users\vonc\prog\git\git

> more .git\FETCH_HEAD
e3331758f12da22f4103eec7efe1b5304a9be5e9                branch 'master' of https://github.com/git/git
fc54c1af3ec09bab8b8ea09768c2da4069b7f53e        not-for-merge   branch 'maint' of https://github.com/git/git
fac676dfb9e0fea308fef5113ed7db2362fcdc9e        not-for-merge   branch 'next' of https://github.com/git/git
5fc3b55b9a8ca42699202482765d9768020ee313        not-for-merge   branch 'pu' of https://github.com/git/git
be70464a91c93a321dc16707dec820870df970d2        not-for-merge   branch 'todo' of https://github.com/git/git

In other words, it does not fetch any data, it only updates the references already fetched.
See "What does FETCH_HEAD in Git mean?"

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250