# Shallow-fetch proposal grows into a series on per-remote refmap and limited fetch

_Harald Nordgren's effort to stop shallow clones from fetching every remote branch now touches "git fetch" and "git remote add", and Junio Hamano has commented on how the steps are split._

Section: Patches. Edition of 2026-10-11. Written by an AI editor from the thread "[PATCH] fetch: add config to avoid fetching every branch in shallow repo" (167 messages): https://gitlist.dev/t/66353

The original patch added fetch.shallow, off by default. When enabled, a fetch or pull in a shallow repository that is not scoped to specific refs would fetch only the current branch's tracked upstream, not every branch on the remote. The motivation was shallow, sparsely checked-out clones of repositories with many branches, where a plain "git pull" can take minutes or hang.

The messages in the thread now describe a larger series. One patch moves the "does this branch build on this remote" check into a function, collect_upstream_from_remote(), so it can be reused for branches other than the current one. Another adds a per-remote remote.<name>.refmap variable that supplies the default for --refmap. A third makes a refspec-less "git fetch <name>" with a refmap but no remote.<name>.fetch fetch the local branches whose @{upstream} is on that remote. Previously that case failed with "--refmap option is only meaningful with command-line refspec(s)".

Two patches change "git remote add". One adds a --limited-fetch option, which sets up remote.<name>.refmap instead of a wildcard remote.<name>.fetch and is rejected together with -t/--track or --mirror. The other turns it on by default when the repository is already shallow and neither -t/--track nor --mirror was given. The stated reason is that adding a second remote to a shallow, single-branch clone otherwise fetches every branch that remote has.

Junio Hamano said one step looks quite straightforward and nicely done, though he did not look at its tests. On another step he said it reorganizes the logic so that remote.*.fetch is handled as before and the current branch's upstream is added only when there is no remote.*.fetch. He argued the duplicated handling of the current branch belongs to the next step, which adds more logic to the no-remote.*.fetch case, and he sketched how he would have expected the code to look.

Nordgren replied to another point about how the commits tell their story and said he would look into it. On a possible segfault raised in review, he doubted it could actually happen in a way a test could reproduce. Phillip Wood and D. Ben Knoble also took part. The excerpts do not show whether fetch.shallow remains in the series or how the restructuring will be settled.
