Article View: linux.kernel.git
Article #895[PATCH v10 5/5] remote: default to --limited-fetch in a shallow repository
From: "Harald Nordgren via GitGitGadge...
Date: Tue, 20 Oct 2026 13:42
Date: Tue, 20 Oct 2026 13:42
146 lines
16399 bytes
16399 bytes
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.
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.
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) {
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 0168d5abfe..f3b5905e9e 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -137,6 +137,66 @@ test_expect_success 'filters are listed by git remote -v only' '
test_grep ! "\[blob:none\]" out
'
+test_expect_success 'add remote -t keeps an explicit refspec in a shallow repository' '
+ test_when_finished "rm -rf shallow-add" &&
+ git clone --no-local --depth=1 --branch main --single-branch \
+ one shallow-add &&
+ (
+ cd shallow-add &&
+ git remote add -t main upstream ../two &&
+ test_cmp_config "+refs/heads/main:refs/remotes/upstream/main" \
+ remote.upstream.fetch
+ )
+'
+
+test_expect_success 'add remote keeps the wildcard refspec in a full repository' '
+ test_when_finished "rm -rf full-add" &&
+ git clone --no-local one full-add &&
+ (
+ cd full-add &&
+ git remote add upstream ../two &&
+ test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+ remote.upstream.fetch
+ )
+'
+
+test_expect_success 'a remote added in a shallow repository defaults to --limited-fetch' '
+ test_when_finished "rm -rf shallow-add" &&
+ git clone --no-local --depth=1 --branch main --single-branch \
+ one shallow-add &&
+ (
+ cd shallow-add &&
+ git remote add upstream ../two &&
+ test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+ remote.upstream.refmap &&
+ test_must_fail git config get remote.upstream.fetch &&
+ git fetch upstream main &&
+ git branch --set-upstream-to=upstream/main &&
+ test_cmp_config upstream branch.main.remote &&
+ test_cmp_config refs/heads/main branch.main.merge &&
+ git fetch upstream &&
+ git for-each-ref --format="%(refname)" refs/remotes/upstream >actual &&
+ cat >expect <<-\EOF &&
+ refs/remotes/upstream/HEAD
+ refs/remotes/upstream/main
+ EOF
+ test_cmp expect actual
+ )
+'
+
+test_expect_success '--no-limited-fetch overrides the shallow-repository default' '
+ test_when_finished "rm -rf shallow-add" &&
+ git clone --no-local --depth=1 --branch main --single-branch \
+ one shallow-add &&
+ (
+ cd shallow-add &&
+ git remote add --no-limited-fetch upstream ../two &&
+ test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+ remote.upstream.fetch &&
+ test_must_fail git config get remote.upstream.refmap
+ )
+'
+
test_expect_success '--limited-fetch works in a full repository too' '
test_when_finished "rm -rf full-add" &&
git clone --no-local one full-add &&
--
gitgitgadget
Technical Details
Message-ID:
<552bf08971be5204311c96bf232b5da49e852db1.1792503778.git.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72534-linux-kernel-git=dewy.ruReferences:
<pull.2412.git.git.1789829246437.gitgitgadget@gmail.com> <pull.2412.v10.git.git.1792503778.gitgitgadget@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72534-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v10 5/5] remote: default to --limited-fetch in a shallow
repository
Date: Tue, 20 Oct 2026 13:42:58 +0000
Organization: Usenet Network
Message-ID: <552bf08971be5204311c96bf232b5da49e852db1.1792503778.git.gitgitgadget@gmail.com>
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com>
<pull.2412.v10.git.git.1792503778.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="3866681"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:mLJ0FMpF1lLqLwkBbz2EDahCOpo= sha256:NC0NlPfM5b9yRoL4gE/THbL+RxCB9VIceqtwB1Cv3LI=
sha1:6g3P9sYxhlkv+GvZtWZr2zQxpdg= sha256:vLcsqVUaSoivL7KjQ77JGt3/EcEagG4D1bm6YbpnXBc=
List-ID: <git.vger.kernel.org>
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 33E26110D24; Tue, 20 Oct 2026 16:53:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 1.611
X-Spam-Level: *
X-Spam-Status: No, score=1.611 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_SBL_CSS=3.558,
SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001]
autolearn=no autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id BuSxSsPHS8R3;
Tue, 20 Oct 2026 16:53:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72534-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 672A9110D02; Tue, 20 Oct 2026 16:53:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 8B1D248292; Tue, 20 Oct 2026 13:44:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792503810;
b=rerkcvdjB2juD3Q4hGnBvGo5r7VPuteCSa7ziIvSjIp0gEolZl+JY3m9WcwJp089WUlD
bry2Bm0etLqkjNiMVWCfN7gUCRdNd2ZyArSM5oHdHZ16zUz/4FMkVqbHmkT7ngwxNcAYO
M4BVlUDUEwGFHTRio3BLfQBb3qJOZNDOKr0oax/1JbCnykNi88EMblRWFibpDCqct7sG9
WeNoMC5ORGbzrfbb9hvk9FXr7VHxEVkWG1MVlsTdpynD03whOt/upNIq8YjFfvJc6Rao2
tQx8KkAH/3EgyQ9o342BZmIwZ7wmBS6b6xIRL+6+IxapU2fMdCbfXAaJx14e1rn+5vw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792503810;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-Id:In-Reply-To:References:From:Date:Subject:Fcc:
Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:To:Cc;
bh=yfjclvMCidjgI1/hccxT+IR4akQ2bjn8JTa94E/11Xk=;
b=MI7jwYv5+bRTi9N94n50FekygHjKX07oGeCuoYDGE4hmGYtkpztG3vmrxKva54O4jobt
CR6n3oO6NIfNR5kzFC9IeURlCD4CBpXgbYOthNCSJPqnyKp7iRQHUnsVf5DqYyHgrnzsM
bmm1nJkrhoEjGC/Bkum0HM9fpT3M11sgSHX/0hsL4lsO2CQygR3CG67h7/6JmikCBGLAI
c2Y6XxPEMPU70GeBnca/Cu3WmkUfwGVGiu/9sKVu3C15HPuo5SNzLJUchjriO7zIxPPXy
u6kN7INiEo62efrn9QnZHkPKLC2jQaC4SVKJGdF0NspN7wMln0XBiSJlqwa/t8S47Hw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rEFlnVMF;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id D6A7B60A6F45;
Tue, 20 Oct 2026 13:43:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rEFlnVMF
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792503805;
b=PhCEexQbeubbcQPiqTErROH4/DPD6iMO75jnKXGfV2XKi+WoQWxw4acZnX+L3rnFHN7o
l+p/gQvUCFe7BDGc9w7fv3pakg50e3bJaOWVMR/0YFPLbcff0gplYtRHvnjgSkzFcy9Ex
pRXXuqhw2Qvpqs0uY866vN60AezbVIh3ePoysaanwr3kGShrNuOlcZwbhW9yRO30vWv4f
XlG33mvBRscFr/5YSbLxlQ1xYxsfHma7+jZNeEeukHwE+gn30UVCeplAehpYMwBThW2jf
NW5d72QwOwB0Z1+6QuGWyDymyRnB6b3CfKbssgjJpEOVRpxEY9v6P/5m9xmI+E/vT4g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792503805;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To:
References:From:Date:Subject:Fcc:Content-Type:
Content-Transfer-Encoding:MIME-Version:To:Cc;
bh=yfjclvMCidjgI1/hccxT+IR4akQ2bjn8JTa94E/11Xk=;
b=FZV/k3Kxxdt/MaRVlcbtzrcwzhivg5yZbd8s+FPRYsvWyYYr2oMWmzv+Of9ePhT0k31U
jYOfoQ6HtS2YzA3Q9wc894yuuMUFXyN9t29rM05iO3hlgYAQWbC5dFntGlp58ktgcm0Al
VCR557zPz7d+QwsmC9svKV/vV0cAeHLwoy7B9q0jDnp75mNqvluOTjTRZ/jXuvSmwcZmX
9VEWlVj+vIDIkwa6oh7nkath3WJZNsM1WvFC+hIpOpyQtjUrgF7DBBiAJ44T9TsOKDx5o
QlPjbBefY+yrFmMC48npdRGWJ0WuMkOTGWj5ulzgay2RZrkAA7G2SGMHlIJZJSyVVCw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rEFlnVMF;
arc=none smtp.remote-ip=74.125.82.179
X-Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id A084A60A380C
for <git@vger.kernel.org>; Tue, 20 Oct 2026 13:43:24 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A084A60A380C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-35cd4e8bdbdso7707364eec.1
for <git@vger.kernel.org>; Tue, 20 Oct 2026 06:43:24 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792503804; x=1793108604; darn=vger.kernel.org;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:references:in-reply-to:message-id:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=yfjclvMCidjgI1/hccxT+IR4akQ2bjn8JTa94E/11Xk=;
b=rEFlnVMFzx1bsKTCH1sNl0Kv7ctjiffFZbKkTCjoetXa3TWx5dTD4m1o54KxzjzOjA
mhpnJwK41jiW9BE5Aj3nY3ipKFUiBw0SK2rA47EAUQzGp0WjVz3Gdkhyb2eaqzdD9eYo
bSF+nOfeB6xcMZ+G1wrJz+mXBKjZPNvdtJB2jiDbWdWtoEeSnzRS+du1dp15PBlCko0R
LdDTpYu5QR5lCQtyj1UVLDVMvCIagFWsAsTARUNuHFj+UYiqne0i27W96/Wlym0WdzRn
6EBNQaEnsNYdSXhI8U/RXppBxffgmJprPed12i/wdsoas8A9kZ35O0BYLWHzxaDz+SrT
1xSA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792503804; x=1793108604;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:references:in-reply-to:message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yoA9VXwhwD4HByZxgeae6pyocKowjXDG4zdqyTWAxMOZuhNEqbK64R1dX9uYy
oGMATuZZg==
X-Received: by 2002:a05:7301:424b:b0:359:ef9:9be3 with SMTP id 5a478bee46e88-361a1667375mr15770948eec.11.1792503803418;
Tue, 20 Oct 2026 06:43:23 -0700 (PDT)
X-Received: from [127.0.0.1] ([134.33.77.25])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-360813b684dsm41112754eec.10.2026.10.20.06.43.22
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 20 Oct 2026 06:43:22 -0700 (PDT)
X-In-Reply-To: <pull.2412.v10.git.git.1792503778.gitgitgadget@gmail.com>
X-Fcc: Sent
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: Phillip Wood <phillip.wood123@gmail.com>,
"D. Ben Knoble" <ben.knoble@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>