From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.170 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== 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== 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 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 ; Mon, 30 Nov 2026 13:46:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E1BC606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-8b51389f58cso111958967b3.3 for ; Mon, 30 Nov 2026 05:46:25 -0800 (PST) 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) 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) Message-Id: <955040d79c11d770844958ca68e92bf452906f8c.1796046376.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Harald Nordgren via GitGitGadget" Date: Mon, 30 Nov 2026 13:46:15 +0000 Subject: [PATCH v17 6/7] remote: add "git remote add --limited-fetch" Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , "D. Ben Knoble" , Matt Hunter , Kristoffer Haugsbakk , Harald Nordgren , Harald Nordgren From: Harald Nordgren A remote added the ordinary way tracks every branch it has, via a wildcard remote..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..fetchRefmap and remote..fetchUpstreams instead of remote..fetch, so that "git fetch " 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 --- 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 ] [-m ] [-f] [--[no-]tags] [--mirror=(fetch|push)] +git remote add [-t ] [-m ] [-f] [--[no-]tags] [--mirror=(fetch|push)] [--[no-]limited-fetch] git remote rename [--[no-]progress] git remote remove git remote set-head (-a | --auto | -d | --delete | ) @@ -75,6 +75,12 @@ the `refs/remotes//` namespace, a refspec to track only __ is created. You can give more than one `-t ` to track multiple branches without grabbing all branches. + +With `--limited-fetch` option, instead of a `remote..fetch` refspec +that tracks all branches, `remote..fetchRefmap` and +`remote..fetchUpstreams` are set up so that a refspec-less +`git fetch ` only fetches branches our local branches are built +on. See linkgit:git-config[1] for details. ++ With `-m ` option, a symbolic-ref `refs/remotes//HEAD` is set up to point at remote's __ 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