Article View: linux.kernel.git
Article #1615[PATCH v12 4/5] remote: add "git remote add --limited-fetch"
From: "Harald Nordgren via GitGitGadge...
Date: Tue, 27 Oct 2026 12:24
Date: Tue, 27 Oct 2026 12:24
139 lines
16086 bytes
16086 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 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 | 28 ++++++++++++++++++++++------
t/t5505-remote.sh | 16 ++++++++++++++++
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc
index 315100409d..1f490819ba 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` 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.
++
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..5f8a8a2f71 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,22 @@ 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);
+ } 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 5fbfcb0848..90cba75f93 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -137,6 +137,22 @@ 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_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:
<97650da87045958a769c3ac66ca5afd1d3ec390a.1793103884.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-73485-linux-kernel-git=dewy.ruReferences:
<pull.2412.git.git.1789829246437.gitgitgadget@gmail.com> <pull.2412.v12.git.git.1793103884.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-73485-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v12 4/5] remote: add "git remote add --limited-fetch"
Date: Tue, 27 Oct 2026 12:24:43 +0000
Organization: Usenet Network
Message-ID: <97650da87045958a769c3ac66ca5afd1d3ec390a.1793103884.git.gitgitgadget@gmail.com>
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com>
<pull.2412.v12.git.git.1793103884.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1534345"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RwBBegoB2SFkmDLGJ4CIzeiaB+8= sha256:zeIUVTixFHTPz8y1B2r+zbXaq0DixfR02Nr5gWrV/UI=
sha1:fWzxB8AS6cN1QR20ALlNhYydh5k= sha256:X8jJcSAqu1S9w1tXkM7CXp/cgCs1pCWyFqL4AO6N6E8=
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 4597A125BFC; Tue, 27 Oct 2026 15:32:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.047
X-Spam-Status: No, score=-2.047 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.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, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=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 Fwl32wVj6AtT;
Tue, 27 Oct 2026 15:32:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-73485-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 8CF28125BF5; Tue, 27 Oct 2026 15:32:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id DCD626089E5; Tue, 27 Oct 2026 12:25:44 +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=1793103897;
b=P/ZSJhWiVinkMESX8i1KZP+pUsRkPYwoL2DJYNN4hNnrld8YvLn/qRgohskyQh5xPbkG
l7PAo33MBlxxyL6vVie50RflDtSQtoFT/BQiLV/5Ri7o09ECLHkuUY+A89eLa5G/DmZA8
pXjo4vU3PtJV7bCFzV9HuX0opObEWYIfYjsHNt4pLbgNQ9QCjMtky0parD1IcwUQMuhJu
2H/wN8z6lqRqSzHvx6PeqMYogr6/wMq7GXl/WE3f06PxS0jGF7r3pPUIIIVnPP2C00CIq
BG2gBqj7YTmknToi382rEmlLwQKm/qPwp2egucLOTbw0LLEtpcFF/eFkG0N6ANJGWMw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793103897;
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=Qb6kEjTAX9LgnmorcutDk5fX1OCgdO5K4pGR7JdvRII=;
b=0ArdcNm70vAPTWU29lK04Y68NPwTof9nPJFXiB/yjhuOnqeJm2/Es5b6mjyBD9M6Eq2f
AyE++ioLCfxn97MndOqguEa9Ge4QkXWGMrQuU9Cj305rFY/UVSILUzyI8Z+4Ck96M5JPV
b3ksavFijmpBvjnNa8Ri1HwJjroocRDeFJFX3sdmyzYIvuxBOu0e3o7pnM4WILVW787wx
ulZNXZWmyrJ3sZttxN85K8XTvKbE0wwuws0JwfZGBydCLIpFNvxJd0ZQnGaaAB1eSQpdH
+pl6UQdLWSVF6Q2lKgd7M0cR+7JIMCtVP5K8Mxz4b/EiIditkaAjDWOsOGYzgH4EXOA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
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 8A6DB60A261F;
Tue, 27 Oct 2026 12:24:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.171
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793103891;
b=Q/5NtI/SzGlx6uH80e83hiTln7DduIumOKkRVExE3+DrC68imb0oaHHFISCxODA+F/xb
fNEyDkRK2FTtGNOfWv6Vk5nWXOmBFMp+6wOgeyDA474uOkNosEewV+f7zmC5O/0vwCpWc
vm7pjMa66VXW4Fcu3s0tC96uDxbj1voOZLk5KmB6MxVUQQPlC9lPbWhE8BlmCKMOYm4xy
oeOljrznmtlKqsz+nSz6QqhRkxWng8DpfPBzaPlj6zIM61ss5D08fH8JG8fpI1cDQJ1V9
7iTbvHe6R+JD8Kpd2nhDc0TSKPXJCdaD4sgPKeoxgZj2Cf8VCCIZYCl++/u4a2Drq/w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793103891;
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=Qb6kEjTAX9LgnmorcutDk5fX1OCgdO5K4pGR7JdvRII=;
b=vrKLvDJfpnxk2GNUqOIHvqZZGhcqFlbiYANVMcEstiYDvCW8KFPRLckpelYhou7XQJ3Y
omRfwCp911vbhDukwbzwzMsUmuM2HbMPGJYJor4HUo4BifwAvKw3kVhKF+jpQJCYIXxKs
tY9TzGAQjp6wO4IFH8eqf9AhNwn7jgpW4J9IszMx4+PZMyT77EQRkeKU0tdqJ0vxTUxiP
67gumL83JLQa9+FtR+9Qdyw3xszjpUG+I6Ako6cD0Uxjf2u4SbgqEXJ6RS6q7xH8Z/C57
xGY4PXJQ/X5qmatXv8WDvihg8yuiruxm5OfU1tZ4LbUY/9UO9HjEkqHqq5R+fn7Awdg==
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=g97yMEln;
arc=none smtp.remote-ip=209.85.128.171
X-Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171])
(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 59EEC60A261E
for <git@vger.kernel.org>; Tue, 27 Oct 2026 12:24:51 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59EEC60A261E
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-f171.google.com with SMTP id 00721157ae682-8726acc5eadso31631907b3.0
for <git@vger.kernel.org>; Tue, 27 Oct 2026 05:24:51 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1793103890; x=1793708690; 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=Qb6kEjTAX9LgnmorcutDk5fX1OCgdO5K4pGR7JdvRII=;
b=g97yMElnxFJgBTT+X8v26XDHLZU8m7rnoDrqjMVFSlzWhLlPOCspyqsCHjsrOJNhVH
nfEZR/wthQp33Rfsy+SM1ioHPYNOsM0hLY0xtJYJvujDsPj4FOjiZ5CmxJPzoZPkDNi6
4YCYnXmjBjSWKIsATMCXLkYdMPo4zWBEHBhXj2wmAIqbc1TS+Tf2YPRmtC1br9ArF9ci
3iBqOLH5bY5xWUAuEi8qTDKQdHD22Lj8coxmSS0ZM0pTzqZZPc7PLyfQfQs9tV33mQ99
qw/68jmkR7jy2T20SKJCCDNxpKCR6KdEU6pz1eKAR+A2Za6OSFcMfuKMXf9vqAEfV9wE
05RQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793103890; x=1793708690;
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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Mb2pLgAPhG19MjkrJdVP1i6TQO5ErS7V7yD56jjHVqAt/Cs/aIog/6sQ==
X-Received: by 2002:a05:690c:ec5:b0:8b0:e13c:2853 with SMTP id 00721157ae682-8b166b9a46fmr80164157b3.15.1793103890134;
Tue, 27 Oct 2026 05:24:50 -0700 (PDT)
X-Received: from [127.0.0.1] ([172.215.147.118])
by smtp.gmail.com with ESMTPSA id 00721157ae682-8b19e64c780sm10012897b3.43.2026.10.27.05.24.49
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 27 Oct 2026 05:24:49 -0700 (PDT)
X-In-Reply-To: <pull.2412.v12.git.git.1793103884.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>