Re: [PATCH] fetch: add config to avoid fetching every branch in shallow repo
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 23, 2026, 15:34 UTC
- Message-ID
- <xmqq5wzwc76w.fsf@gitster.g>
- In-Reply-To
- <05d0e6e0-e156-4a2a-95a0-4986ab18ef49@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 16 quoted lines
>> when 'remote.*.fetch' is configured to signal that special mode,
>> 'git fetch' would:
>>
>> - Find each local branch that has its '@{upstream}' set to a branch
>> at the remote we are fetching from.
>>
>> - Fetch these branches at the remote that our local branches care
>> about.
>
> I can see that being useful fetch mode for a remote that we've already
> fetched from, but for a newly added remote there will be no local
> branches with their upstream set to it because "git branch
> --set-upstream-to" fails if the upstream does not already exist. So I
> like the idea for fetching from existing remotes, but it leaves us with
> a chicken-and-egg problem when adding new remotes, so I'm not sure how
> it would work in practice.Just like with "git push there :", you prime the pump by explicitly doing something (for "push", you do "git push there mine" to express your preference to work with branch 'mine' and share it with the remote).
So if we are to allow customizing the refspec used for fetch with "git remote add", you might do:
$ git remote add --fetch=: second https://ho.st/git/second
which creates:
[remote "second"]
url = https://ho.st/git/second
fetch = :(Note: I am not sure if ":" is a good special token to express this mode of fetching, as I said earlier).
Your initial "git fetch second" without any other arguments will be a no-op. You may decide to work on top of their 'main' branch by running:
$ git fetch second main:refs/remotes/second/main
$ git checkout -b topic -t second/mainAt that point, the local branch 'topic' is built on top of their 'main' branch by having its @{upstream} set to that remote-tracking branch. After that, running "git fetch" will update 'second/main' and no other remote-tracking branch.