Re: [PATCH] fetch: add config to avoid fetching every branch in shallow repo
From: Phillip Wood <hidden>
Date: 2026-09-23 15:14:38
Hi Harald On 22/09/2026 16:37, Harald Nordgren wrote:
On Tue, Sep 22, 2026 at 4:53 PM Phillip Wood [off-list ref] wrote:quoted
On 22/09/2026 14:00, Harald Nordgren wrote:quoted
quoted
quoted
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