Article View: linux.kernel.git
Article #4121[PATCH v17 7/7] remote: default to --limited-fetch in a shallow repository
From: "Harald Nordgren via GitGitGadge...
Date: Mon, 30 Nov 2026 13:46
Date: Mon, 30 Nov 2026 13:46
147 lines
16635 bytes
16635 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>
Adding a second remote to a shallow 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 in the first place (for example with --single-branch), 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 | 9 +++++-
builtin/remote.c | 5 ++-
t/t5505-remote.sh | 60 +++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc
index 39b9281293..2216a2a752 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,9 @@ With `--limited-fetch` option, instead of a `remote.<name>.fetch` refspec
that tracks all branches, `remote.<name>.fetchRefmap` and
`remote.<name>.fetchUpstreams` are set up so that a refspec-less
`git fetch <name>` only fetches branches our local branches are built
-on. See linkgit:git-config[1] for details.
+on. See linkgit:git-config[1] for 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 18fe6f697c..8163fcc618 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) {
bool 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 679d22fcec..61cb53a589 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -144,6 +144,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.fetchRefmap &&
+ test_cmp_config true remote.upstream.fetchUpstreams &&
+ test_must_fail git config get remote.upstream.fetch &&
+ git fetch upstream main &&
+ git branch --set-upstream-to=upstream/main &&
+ 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.fetchRefmap &&
+ test_must_fail git config get remote.upstream.fetchUpstreams
+ )
+'
+
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:
<49ec3aaed9940c56724943501be7b06e6402bcbd.1796046376.git.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76679-linux-kernel-git=dewy.ruReferences:
<pull.2412.git.git.1789829246437.gitgitgadget@gmail.com> <pull.2412.v17.git.git.1796046376.gitgitgadget@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76679-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v17 7/7] remote: default to --limited-fetch in a shallow
repository
Date: Mon, 30 Nov 2026 13:46:16 +0000
Organization: Usenet Network
Message-ID: <49ec3aaed9940c56724943501be7b06e6402bcbd.1796046376.git.gitgitgadget@gmail.com>
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com>
<pull.2412.v17.git.git.1796046376.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1439166"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YPiq9mvAJ881vYz4kSGGafrfYgU= sha256:xbOHGVb1vpw0rQwpPLnpIOkFokearmTGgU6KP82KF78=
sha1:Nld4LrM1QediCE5tyzXwjA8rz70= sha256:I8uy5PON6jUGcmneEOUagJF9AZoqi3QkjfawEdON8ok=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 2EA28125FF1; Mon, 30 Nov 2026 16:52:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[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.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham 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 M0kRbyDttfJY;
Mon, 30 Nov 2026 16:52:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76679-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 776A1125FED; Mon, 30 Nov 2026 16:52:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id A73793148E; Mon, 30 Nov 2026 13:52:22 +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=1796046742;
b=dsPt890M0tuCD+KOr3ikQ8O4NoRYfDUa5B0n/rMKjDdPI3LVaxlCXM5gxvUl+g0qGMz3
fpTBZM4IthCRn6h6ThO8RdPUscTHe1uS3zL/Uovfg8sZ707t0Qdj1ZenSObcgRIs/1MhG
zpwZIwTUMZ+uDDylkYeq34y/6TgXcOi1zaCd26zUC6E+C9ekQKX4Vg095NAYZPEHpdeX/
g1sFn3npogpibVPEPvhpxcAxaXQDn3stzZ8E9+Cf6r9O+Q+Cx3NVR7tH6AcUEIqmhYjuV
cWrG3fl3jiSWTiEr95dvUWqLYVlwamvSYaNWs4DNR5KwCgR7bbd5+6FcPRGlKNc5PtA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046742;
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=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=;
b=I52NTjjCh/SxAUB+UwqA/Hy7ay4YAj3pHnOelDC69Ynjpd0ju5eSmsIfaofSzZLTRxu6
afS6XuAHIu+c1KUqKyMK5W/NCXCn7we/swTLhdj8MCQVOJo+Id81t5r3g/KNvG8bGZF/L
fbjvrZzGRAQVWkzgLEWNSomi6EYtWoW+Qo8JdvahoJXxIDyo1FDXGMy51fRMFd0PocYE1
hwCJ7hX+15uEGoJF9suVuguEGE03uEaBGD7qS/aAMIZAUlVA++hpn4ieP3W6FzSjmLsGk
dsIZmthGJFjPaHxYlHaKP1rqKuU+sdSqIggQktdzy+AHEc8Hi8oyYjOfzqWSvJ+VE4A==
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=20260707 header.b="K8hv/FAd";
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 EE468606A32A;
Mon, 30 Nov 2026 13:52:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K8hv/FAd
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.180
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796046741;
b=OQIuvGbymrLgqq6YjlsT1ooD2d0fDYZh3IT8muaa0evZ7oVSzHF3yKFyyNvVkJ0jQBUA
KtkVCRwlwziDDWXgKwX/lVfKSAFJOubud8x/Q05bx6omVFTjZOfSCOqwOX7FCXsGI2Vvn
5Oegett+hGWQcSdm9wEKOza5AQNFUe0bUaoTKwXZvbky1q3vgeeVagefWL9ID0o2ZfkoH
H06zu49ork7ZmGb5gnZa+jSHL41cQJLDBWKfhEaUSS7lr+SV9cnXnxu0OtgDib8Lm3M+t
maFUcHV3CtHv/3K9ryXfZktq/VQiiS0G6qdlLnbCkdC/E8pCUdv+XM38/+HAlD6bYow==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046741;
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=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=;
b=g3RUL5Y80FPh+SVkFXDMn8dUooyTQqUvPtvjJjqrTmWcTmq61oQRy3YHzSB5fVkT7xwt
h31O6z4h1lcBfYRJN/VsWKiT2X5z/2cl9OHfNePAX0+eWVWn6ivYKPoXLUCrqYh2LHfxa
HOHg+6WJU7kiD8GHDDTr4qjeqsw7Mj0vuR1doFQoE1yiaovZDVCBdLyP1nWLjaU39svAI
2Wrjt8Fd+clvzeoLFquhsRm8v6Mza7NnpLu/EiMpqc1MlgXyRa3h/lA1qAJN0UobraW7M
QBw3SJGplMHL/Cx2R/mJ9KyZbkL7UXhBVB8Nszt7q9/FPhlkvoX5c37p8okJR6oRitw==
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=20260707 header.b="K8hv/FAd";
arc=none smtp.remote-ip=209.85.210.180
X-Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180])
(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 B246B606A31C
for <git@vger.kernel.org>; Mon, 30 Nov 2026 13:52:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B246B606A31C
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-pf1-f180.google.com with SMTP id d2e1a72fcca58-8b4c8b51b58so6240227b3a.1
for <git@vger.kernel.org>; Mon, 30 Nov 2026 05:52:20 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796046740; x=1796651540; 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=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=;
b=K8hv/FAddbZH29IlQ+koQmVrF25C8bHrynNkgMzjVEpe2JHWEqSyOdAlgB51kUbL9z
4qD7mN3y6CIUylCVnL+DZSbGK37dO3STWHvWazCt2ppJyvbkbLalvn6BElZtxdO8BgGI
fCawRlomm4fbNpdkESHhQPMnl4PLByUHNHEFHVhtRzIFwuxTwVtfHWkOcZ/BuOyDpzN6
s3fbcMnY78TWuveMZ/thPRhfHK6oLZwMEzmCic8IJXXUpXThLwM/1uZ8ijl1B9A1N8/4
utbc3hIBfioEIsdI7ABgG27OR/b2u9kbrgmWDBNzW9AMZG43U3txaEztpxTeMu8DYd1y
6H0A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796046740; x=1796651540;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:references:in-reply-to:message-id:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=;
b=c+jpBsRvgnt8NBENk8EwoxRjnWz+i28dGxHKW/mSw62MvHR8KW6M9Gj/jyvYVy9aR7
4b/7EJtD4a48IDgFQLjWgoYGX/PbyW9bBDwMHuOwpKsr0ry2F57yVkNPtBIIYHOXaK7u
4nAs/nJ92hyfk6h5bxhZOdmvQvF2pYl6upfCVKHKg2UO1q4dsmUZHSlh8149FsZt9Y7u
L6gg3bOoSModTI3Y+WqaQuYIDcU9cLEpS3ze+FNNn6SRuNEUCappNndoNYoYF486IuCC
7w7EIp2TjR6E9nxtsXhMhbFFX5CO8xkxOrCJ0YUtpiUVdEwC2hW/0nWwMiQRPZ+hdiMD
pxTw==
X-Gm-Message-State: APuU4Z8daqCrLh/R+co4IF1ClqJOLPR4bNL360d/F5aoawwkQVYkwC4g
pxdL7MtX0fP7PIM+sKaB9N/r+QWkPE0Jn8OoszjcO+01syESmlIw1cUBpd+RcLId
X-Gm-Gg: AZFdTZek/zsFqdBR/H81FZ7PeR+o5eAXYyapKcm34UWiDQdpVLzapvW52uzBQax9KUq
C2fWciTsAzt94AmdqQFZHDG/wwJhUeAi/IbUa4+b+RNNm+aFTfyYFvxKHVuflcz0xBjs5oRPpjV
uJ56vpwEpRMvmD0zGDzyXB3A08NNqZ7LxHRrpZvT/jMEPdyBltYt8l42p4bZcJMbI8dSX2gBWGY
G424QXSakNzi4zvEsc59CoVYsGylmtTVfhCCFiY9R6nfqnN9B0y0lJo757Ra1/CnuTaIfkojsP7
HsJCIKrP5kxiKQeY4Oy2kWK84cyr5jtfPM1VW2ZOHDVhkIiGtQxO1biU1nSjmPlzEMvKNaZGBAG
i3ZtZty57Rs2nG3z0RPFB4d6G41pJi4v3oLjWLAlsG8d5L4g0IGwvqBIpsuYaMaDJ6+OGdbc50W
ON5HETMmjmRv/lN23t/OlGA668tq/aBb+aQkZe365T6LSEDawNpsH5ksoufvxZB+hxG8DYNXQNP
ONnlKVkc1xLy4729v07ULq8U2fjeIYFm7h2/K1W4OT0AyK+LGPKNye69Q+Fx+FoqlXiYIFDdD71
VCKxNoVfvG7LD4JvYhtIvR55bUP/ZVw=
X-Received: by 2002:a05:690e:812:10b0:679:9bc4:cc03 with SMTP id 956f58d0204a3-67df4452f0cmr9371980d50.69.1796046384997;
Mon, 30 Nov 2026 05:46:24 -0800 (PST)
X-Received: from [127.0.0.1] ([20.49.63.207])
by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921787fd72asm156997366d6.12.2026.11.30.05.46.24
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 30 Nov 2026 05:46:24 -0800 (PST)
X-In-Reply-To: <pull.2412.v17.git.git.1796046376.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>,
Matt Hunter <m@lfurio.us>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>