Re: [PATCH v10 5/5] remote: default to --limited-fetch in a shallow repository
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Oct 24, 2026, 15:13 UTC
- Message-ID
- <CALnO6CBA3oQMm--3VxhbUdDmXfAGjZo9H5bFxWOGUCY=GADk3w@mail.gmail.com>
- In-Reply-To
- <552bf08971be5204311c96bf232b5da49e852db1.1792503778.git.gitgitgadget@gmail.com>
On Tue, Oct 20, 2026 at 9:43 AM Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 10 quoted lines
> > From: Harald Nordgren <haraldnordgren@gmail.com> > > 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.<name>.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…
Show 5 quoted lines
> 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 ;)
Show 56 quoted lines
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
> 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 _<name>_ for the repository at
> _<URL>_. The command `git fetch <name>` can then be used to create and
> update remote-tracking branches `<name>/<branch>`.
> +
> +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 <name>` does
> +not need to negotiate history for every branch the remote has.
> ++
> With `-f` option, `git fetch <name>` is run immediately after
> the remote information is set up.
> +
> @@ -79,7 +84,8 @@ With `--limited-fetch` option, instead of a `remote.<name>.fetch` refspec
> that tracks all branches, `remote.<name>.refmap` is set up so that a
> refspec-less `git fetch <name>` 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 <master>` option, a symbolic-ref `refs/remotes/<name>/HEAD` is set
> up to point at remote's _<master>_ 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 ;)