From: D. Ben Knoble Date: Sat, 24 Oct 2026 15:13:05 GMT Subject: Re: [PATCH v10 5/5] remote: default to --limited-fetch in a shallow repository Message-ID: In-Reply-To: <552bf08971be5204311c96bf232b5da49e852db1.1792503778.git.gitgitgadget@gmail.com> On Tue, Oct 20, 2026 at 9:43 AM Harald Nordgren via GitGitGadget wrote: > > From: Harald Nordgren > > Adding a second remote to a shallow, single-branch clone used to > still fetch every branch that remote has, since "git remote add" > always set up a wildcard remote..fetch refspec regardless of > how shallow the repository already was. That defeats the purpose of > having cloned shallow and single-branch in the first place, and can > make a plain "git fetch" on that remote hang or take a very long > time on a repository with many branches. First we focus on "single-branch shallow clones", but… > Turn --limited-fetch on by default when the repository is already > shallow and neither -t/--track nor --mirror was given, so that > adding a remote there does not by itself commit to following every > branch it has. --no-limited-fetch keeps the previous behavior for > whoever wants it. …now we only care about shallow. I think that's reasonable, since we don't have a way to track "was cloned with a single-branch" (and it's not really the key criterion anyway), but the wording begged the question ;) > Signed-off-by: Harald Nordgren > --- > Documentation/git-remote.adoc | 8 ++++- > builtin/remote.c | 5 ++- > t/t5505-remote.sh | 60 +++++++++++++++++++++++++++++++++++ > 3 files changed, 71 insertions(+), 2 deletions(-) > > diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc > index f8764394e7..f43d707c91 100644 > --- a/Documentation/git-remote.adoc > +++ b/Documentation/git-remote.adoc > @@ -57,6 +57,11 @@ Add a remote named __ for the repository at > __. The command `git fetch ` can then be used to create and > update remote-tracking branches `/`. > + > +If the repository is already a shallow repository (see linkgit:git-clone[1] > +`--depth`) and neither `-t`, `--mirror` nor `--no-limited-fetch` is given, > +`--limited-fetch` is turned on by default, so that `git fetch ` does > +not need to negotiate history for every branch the remote has. > ++ > With `-f` option, `git fetch ` is run immediately after > the remote information is set up. > + > @@ -79,7 +84,8 @@ With `--limited-fetch` option, instead of a `remote..fetch` refspec > that tracks all branches, `remote..refmap` is set up so that a > refspec-less `git fetch ` only fetches branches our local branches > are built on. See the `--refmap` entry in linkgit:git-fetch[1] for > -details. > +details. `--no-limited-fetch` explicitly disables this, overriding the > +shallow-repository default described above. > + > With `-m ` option, a symbolic-ref `refs/remotes//HEAD` is set > up to point at remote's __ branch. See also the set-head command. > diff --git a/builtin/remote.c b/builtin/remote.c > index a7c13946d1..8c4497cccd 100644 > --- a/builtin/remote.c > +++ b/builtin/remote.c > @@ -16,6 +16,7 @@ > #include "rebase.h" > #include "refs.h" > #include "refspec.h" > +#include "shallow.h" > #include "odb.h" > #include "strvec.h" > #include "commit-reach.h" > @@ -238,7 +239,9 @@ static int add(int argc, const char **argv, const char *prefix, > > if (!mirror || mirror & MIRROR_FETCH) { > int use_limited_fetch = mirror == MIRROR_NONE && track.nr == 0 && > - limited_fetch == 1; > + (limited_fetch == 1 || > + (limited_fetch == -1 && > + is_repository_shallow(the_repository))); > > strbuf_reset(&buf); > if (use_limited_fetch) { I didn't read the tests, but the code looks short and sweet ;)