Re: [PATCH] fetch: add config to avoid fetching every branch in shallow repo
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Sep 23, 2026, 15:14 UTC
- Message-ID
- <c5710264-d901-4b23-81f9-fc69f8268826@gmail.com>
- In-Reply-To
- <CAHwyqnUjDJNjER2AxFXOR6G3sOJKpsXj-agzmm7410_QAFu8PQ@mail.gmail.com>
Hi Harald
On 22/09/2026 16:37, Harald Nordgren wrote:
Show 22 quoted lines
> On Tue, Sep 22, 2026 at 4:53 PM Phillip Wood <phillip.wood123@gmail.com> wrote: >> >> On 22/09/2026 14:00, Harald Nordgren wrote: >>>>> If it is the former then we should think >>>>> how we can improve the behavior of "git remote add" in a sparse >>>>> repository to prevent it adding a wildcard fetch refspec and instead >>>>> setup the new remote to fetch only the branch(es) we're interested in. >>>> >>>> I didn't even consider that, that sounds like an interesting idea! >>> >>> Would you suggest we do that instead of this, or in addition to this >>> fix? >> >> I'd say instead - if we can fix "git remote add" then the problem >> shouldn't arise in the first place which is better than having an opt-in >> config option that most users are probably unaware of. > > That makes a lot of sense. > > However, I think there is info missing on the local side that we can't > get without making a network call to the newly added remote, like its > branches (and default branch). How do we handle that?
There is a "--track" option for "git remote add" to set up the branches that are fetched. Without "--fetch" we could refuse to add a new remote in a shallow repository unless the user tells us which branches to track. That is a bit of a pain, but I think it is better than adding a wildcard refspec that makes "git fetch" unusably slow. We could also perhaps look at the refspecs for the existing remotes and, if they are all fetching the same branch(es?) copy those.
With "--fetch" we could lookup the default branch on the remote and fetch that if "--track" isn't given.
Thanks
Phillip