Article View: linux.kernel.git
Article #4120[PATCH v17 6/7] remote: add "git remote add --limited-fetch"
From: "Harald Nordgren via GitGitGadge...
Date: Mon, 30 Nov 2026 13:46
Date: Mon, 30 Nov 2026 13:46
143 lines
16732 bytes
16732 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>
A remote added the ordinary way tracks every branch it has, via a
wildcard remote.<name>.fetch refspec. That is wasteful for a remote
whose history is only worth following for the branches actually in
use locally, and it can make "git fetch" negotiate history for
branches nobody asked for.
Give "git remote add" a --limited-fetch option that sets up
remote.<name>.fetchRefmap and remote.<name>.fetchUpstreams instead
of remote.<name>.fetch, so that "git fetch <name>" only fetches the
branches already tracked, as described in the previous commit. It
is rejected together with -t/--track or --mirror, since those
already say explicitly what to fetch.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
Documentation/git-remote.adoc | 8 +++++++-
builtin/remote.c | 31 +++++++++++++++++++++++++------
t/t5505-remote.sh | 17 +++++++++++++++++
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc
index 315100409d..39b9281293 100644
--- a/Documentation/git-remote.adoc
+++ b/Documentation/git-remote.adoc
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[synopsis]
git remote [-v | --verbose]
-git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <URL>
+git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] [--[no-]limited-fetch] <name> <URL>
git remote rename [--[no-]progress] <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
@@ -75,6 +75,12 @@ the `refs/remotes/<name>/` namespace, a refspec to track only _<branch>_
is created. You can give more than one `-t <branch>` to track
multiple branches without grabbing all branches.
+
+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.
++
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 fb7e5b114f..18fe6f697c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -179,6 +179,7 @@ static int add(int argc, const char **argv, const char *prefix,
{
int fetch = 0, fetch_tags = TAGS_DEFAULT;
unsigned mirror = MIRROR_NONE;
+ int limited_fetch = -1; /* unspecified */
struct string_list track = STRING_LIST_INIT_NODUP;
const char *master = NULL;
struct remote *remote;
@@ -198,6 +199,8 @@ static int add(int argc, const char **argv, const char *prefix,
OPT_CALLBACK_F(0, "mirror", &mirror, "(push|fetch)",
N_("set up remote as a mirror to push to or fetch from"),
PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt),
+ OPT_BOOL(0, "limited-fetch", &limited_fetch,
+ N_("fetch only the branches we build on, instead of every branch")),
OPT_END()
};
@@ -211,6 +214,10 @@ static int add(int argc, const char **argv, const char *prefix,
die(_("specifying a master branch makes no sense with --mirror"));
if (mirror && !(mirror & MIRROR_FETCH) && track.nr)
die(_("specifying branches to track makes sense only with fetch mirrors"));
+ if (limited_fetch == 1 && track.nr)
+ die(_("--limited-fetch does not make sense with -t/--track"));
+ if (limited_fetch == 1 && mirror)
+ die(_("--limited-fetch does not make sense with --mirror"));
name = argv[0];
url = argv[1];
@@ -230,13 +237,25 @@ static int add(int argc, const char **argv, const char *prefix,
repo_config_set(the_repository, buf.buf, url);
if (!mirror || mirror & MIRROR_FETCH) {
+ bool use_limited_fetch = mirror == MIRROR_NONE && track.nr == 0 &&
+ limited_fetch == 1;
+
strbuf_reset(&buf);
- strbuf_addf(&buf, "remote.%s.fetch", name);
- if (track.nr == 0)
- string_list_append(&track, "*");
- for (size_t i = 0; i < track.nr; i++) {
- add_branch(buf.buf, track.items[i].string,
- name, mirror, &buf2);
+ if (use_limited_fetch) {
+ strbuf_addf(&buf, "remote.%s.fetchRefmap", name);
+ strbuf_reset(&buf2);
+ strbuf_addf(&buf2, "+refs/heads/*:refs/remotes/%s/*", name);
+ repo_config_set(the_repository, buf.buf, buf2.buf);
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "remote.%s.fetchUpstreams", name);
+ repo_config_set(the_repository, buf.buf, "true");
+ } else {
+ strbuf_addf(&buf, "remote.%s.fetch", name);
+ if (track.nr == 0)
+ string_list_append(&track, "*");
+ for (size_t i = 0; i < track.nr; i++)
+ add_branch(buf.buf, track.items[i].string,
+ name, mirror, &buf2);
}
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 8b4c7006ec..679d22fcec 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -144,6 +144,23 @@ test_expect_success 'filters are listed by git remote -v only' '
test_grep ! "\[blob:none\]" out
'
+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 &&
+ (
+ cd full-add &&
+ git remote add --limited-fetch 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
+ )
+'
+
+test_expect_success '--limited-fetch conflicts with -t' '
+ test_must_fail git remote add --limited-fetch -t main upstream ../two
+'
+
test_expect_success 'check remote-tracking' '
(
cd test &&
--
gitgitgadget
Technical Details
Message-ID:
<955040d79c11d770844958ca68e92bf452906f8c.1796046376.git.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76678-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!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76678-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v17 6/7] remote: add "git remote add --limited-fetch"
Date: Mon, 30 Nov 2026 13:46:15 +0000
Organization: Usenet Network
Message-ID: <955040d79c11d770844958ca68e92bf452906f8c.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="1437764"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zrFbpIp67iSmgmknC5SwcPXhduE= sha256:+FwkBN9veUlX0AuaskRo+sSkC/klrJ9KZ+tyGRVAv+Q=
sha1:CkkTnqajsrtBTXZlJhbsqaoXkVo= sha256:vgmye5qkni5oOsPOY5MWb56lyyqa2GNWL7/XTxAHrvk=
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 60D1B125FF1; Mon, 30 Nov 2026 16:46:55 +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 n0D3_Hdfqi_Z;
Mon, 30 Nov 2026 16:46:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76678-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 4E1F4125FED; Mon, 30 Nov 2026 16:46:44 +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 94BA330C72; Mon, 30 Nov 2026 13:46:30 +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=1796046386;
b=cWerZ/DH0bfmjSeZJXXmQvuDQjqRWhdg1S0mTJvoeWxLG8v4bHfs18/5vePPw90QNyN/
uZUnIgxnpqWHyeshH3ZIkaShBMUlzNIeGQ+7w9jqPMJE54/iYiq7as6yWHjeElQ/1aUhW
lqthfP3jHsgdFOfuRbM8YAwkOumiOk9zKdYY1OdkPekkD2sBgSmrDhLZybIuQpYolEV7L
P5/v04QByLPSMiqkO2lmi7RcqvavDq2zChP/CQtLNd2DApH0ynDsP+8a0YxM+mdGuW4i0
17L8Za3ZjWwOGZwVB8wlu3a4EneUUfaU80SrKJbs5XBMp4ihWBNaISyqGWjE2b4dPcQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046386;
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=vbRNLKO3gfTSOvrqwgbMcGUgGCsHsjFQg4+4l8TI+QM=;
b=PknBInNRJknbftYKHYyh+LN2l2GWLfc7syy7wyKyFuqhA3F+Da7tgDXp3uizdj7aiw/G
hEk6uCme1DJ/Sha+ZREZgRB49K6+E/pfaIbInmkbeoSBvG5MB0l5sE6cKhJNBu2F+zXTy
449vYvynTUWc3btwwuwUVH/JA5CoVbprBHPPfQFy++ifVcwk4LYCkEo6oWhIQjY8w1mYy
J7/EnSl39/BcCjevVXjc65uurV7Gt9Whl5t8Hhkq9kOybEgd46BCdVIOf1zvbTn57lEyv
OL0yNR5/nKsxHkF8oHe9phln7bKZNPYAee9js4zQNieNwg+C5YzVYWgh3Omim6UEAPA==
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=JaAU75u5;
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 89815606A338;
Mon, 30 Nov 2026 13:46:26 +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=JaAU75u5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.170
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796046385;
b=nB7AZjwaOYZphhFBx2fySGS3xk/FI7TOWY4cSv3lNEqEe88iVjCY+i9RAtP+dSYLHo6q
SYl0PaJKg86hCG3P3Ia6LYpxjIJ5QCbrrDe64FS4lWoh4CIIaKUqQSgPZStJ3jyA+60kE
PapVvs1N7Gk0CWhcu1lvmxF3eCbthyhrcGPXZUX7PwLi4mJn7kBnaIRFsFSdForak9hNj
dD3P4WPYHK9WwPwmUbSDrMls2UY7OKrZSW1c2L50eU4JvKWwAe4j0yv0vrXzd4cPYx+fh
Bli53+nMXU+sZCxj5hdV0SxOaDsnbAA66Ki5csygO6CNCLMMtZwYCngQIzwuFZCUxtA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046385;
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=vbRNLKO3gfTSOvrqwgbMcGUgGCsHsjFQg4+4l8TI+QM=;
b=DfJ0+XAQd1ush1UHf5Qkz3v4dq0sYT57YcTDropGUWNdaE+9JLnK6gJA+U9E44QpD0CE
B6vf2uTL5sUh+jPD83YnfBWKfbVmdFUWWK4azzeJ320K0X50t25yoRzsc4dieJC3lY+lu
TiRbSWBiLA7/9KkTB78RvSsPMkg0G0ccmk1ebZj+zU33ia7RmwUITPTf0dkWiOECDHghg
GsQDC9XbmqH9ZdeVhXNeHvMq4FUDK7OIMGrfuKQbrbfzYqQQwjAXvtapvHLN3UjDpLYNN
IoYWnUnZVyNOFZ7hewcl3RmV53PCuaumxTNK8cS7WVCxtLViO3OAmJcUtOMePB1IxUw==
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=JaAU75u5;
arc=none smtp.remote-ip=209.85.128.170
X-Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170])
(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 5E1BC606A333
for <git@vger.kernel.org>; Mon, 30 Nov 2026 13:46:25 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E1BC606A333
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-yw1-f170.google.com with SMTP id 00721157ae682-8b51389f58cso111958967b3.3
for <git@vger.kernel.org>; Mon, 30 Nov 2026 05:46:25 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796046384; x=1796651184; 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=vbRNLKO3gfTSOvrqwgbMcGUgGCsHsjFQg4+4l8TI+QM=;
b=JaAU75u5tUfyzGb+lcPj8gfU7vhlsiStNv0YWglGTg9BGxRbbXeBgKbe9rzH2qFzT7
DvL/Oa6kPO+x7y7Y6kKJVcgHYumuMitngoGA3Qt9umKDHhI/mPUSYyAQy5s874brLUDH
0OLmQRmINeKwB1cpUhGUM9oEh6ncii7vOmCZXKiypt5S8/sikJr6ufwQS0YHAUtCsvxR
8vILQmjYD0YeuJXR2HaHlMjunx46tvo48LsQB8J6V0JCW0Xapems4TwIHQNKIEqJwFVu
UjRHADRDXsJJTAO9oWn7aBCcSVSuyrTeGgwzmwRZTBDxdjVet6OyWjEq7N+5nrd7+NCn
Ippg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796046384; x=1796651184;
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=vbRNLKO3gfTSOvrqwgbMcGUgGCsHsjFQg4+4l8TI+QM=;
b=kpsQr62Vr4v7ei/3JAy8TUaMi+ibYbF75Qac71ViSwZVjaFxsjAVc+LxJOnySh3ivt
p9zV4Dn1Snmj9azkG2mlag1ueHZcCgsNq4xctHPN+bdgTEj9kMk+bRzhFjoUVEsyDm6n
PtzhqBvKEY0nUyd2ZuBwE3yRGj7ErCz+5guB9QTLmSJTma1Snl9M8KjD7P8+MoDlLSa1
XngpAdBIZklabMn/OhaOGofAkCQKwdKcn71S6YhIoMj/h0TIs+x7tzr7FbvHKWD9BMst
75vb2GsOiAlx89F2FN6lxdlyfWStWXAZ9DNIJYXHc5SjaDZCbQM26wSIYs0h7Nd47sAn
ix0w==
X-Gm-Message-State: APuU4Z+XcAn6MA3w7983OehBAsDeusC1QgaTGGphkmnp4lnEm0jlkPfl
5hhxxMPSxmEblMqh5KXvoQDd9Isc3VAciQ2Xamz/4VqpP6E+FBv1SrEPfhSFz8Of
X-Gm-Gg: AZFdTZegMYqqAnnDRvHeH3AXAqhJ7+s5wfx4w5n/yxyV/mlmwUBgUx/2OhJYla6PPRO
3SQnreyYIs9mPozNMZTqKL5TTsoF7skpwtGazKb5iGKFk15FVP/FT50dMGbUB7KEPptsg8xYNv+
uba1yLQ1vIYtMHvrJIs5SQJU0yzBlAb4bOqu3yx087q81RuiHp6W1Py0/o+Dsx/Pgw6ke/+e5yH
qlEgApRe3GPo17rc3x772f+Pv71EfztJNsA2JGsWONJN5EWdkOkVa3ax6gmxWpU98sHVrR4nMw4
5MJLrL+0Ppp/UQ43W46aX3c7HTuQBZi/IAXFyjzLAc5GeOPrTLVVZ12PS/sd9Z5iQsAmPxDq1Vd
qPWkFv2F8hc5yoCf+gC+wLd/ZcpNgF9hrK4YHWXW+NzXKFy4Z6E3vby/ho+gyuSHduczE06YDFr
m0kDkMvyJrvPAFqeio0BtqJqFk+POFcdf4QAeSFzEk55h5ZBTy5Y3TJ65mnJJXuBZ8dV2hn/YZS
8pHWbxjOWqw3LT92+qPBDcD0zy5KFX2SLT2jm7LbdHFcq/zUccoqPCAWAEVrmcQ5qLWUjbS4mN6
TcT5ZoV2BzmaKJ/7pZpDyuYLCf2drV0=
X-Received: by 2002:a05:690c:445:b0:8b5:9d75:1855 with SMTP id 00721157ae682-8b59d751d05mr25376537b3.28.1796046384090;
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 af79cd13be357-949bb34ac1esm2548559485a.15.2026.11.30.05.46.23
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 30 Nov 2026 05:46:23 -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>