From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Phillip Wood <phillip.wood123@gmail.com>,
"D. Ben Knoble" <ben.knoble@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH v2] fetch: avoid fetching every branch of a new remote in a shallow repo
Date: Wed, 23 Sep 2026 14:38:38 -0700 [thread overview]
Message-ID: <xmqq7bkb7in5.fsf@gitster.g> (raw)
In-Reply-To: <pull.2412.v2.git.git.1790195720941.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Wed, 23 Sep 2026 20:35:20 +0000")
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> git remote add sets a new remote up to fetch every branch by default.
> In an already shallow repository, that turns the next plain fetch or
> pull into a slow or hanging one, even when only one or two branches
> are ever used.
>
> Add a special fetch refspec, "+:", that fetches only the branches our
> local branches are built on, plus the remote's default branch so a
> brand new remote is usable right away, without needing to first set
> anything up to track it. git remote add now uses it instead of the
> usual wildcard refspec whenever the repository is already shallow.
That's way too much for a single patch. It needs to be split into
digestible chunks, but I offhand do not know how many pieces are
appropriate, so let's think aloud together and try to refine the
design while we do so.
The outline of our design so far should give something like this in
our configuration file.
[remote "second"]
fetch = :+
[branch "topic1"]
remote = second
merge = refs/heads/main
[branch "topic2"]
remote = second
merge = refs/heads/next
In the "fetch only what we build on" mode, we would collect local
branches $X where branch.$X.remote == second and then collect
branch.$X.merge for these local branches. In this case, we would
decide to fetch 'main' and 'next' branches in the end.
But notice that this does not give us sufficient information. There
is no explicit clue that tells that the remote-tracking branches for
this remote 'second' should be stored under refs/remotes/second/
hierarchy. A normal remote that is defined like so:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
does not have such a problem, as it makes it crystal clear that
their branches go under refs/remotes/origin/ hierarchy.
So using "fetch = :+" is *not* a good idea, as I said. Let's scrap
that syntax.
One thing we could do is probably to introduce
[remote "second"]
refmap = +refs/heads/*:refs/remotes/second/*
instead to give this clue (see "git fetch --help" for what a refmap
is; it looks similar to refspec but only defines how their refs are
mapped to our namespace without specifying what to be fetched, which
is exactly what we need here). We do not use remote.second.fetch at
all.
It would be an easy first step to teach that an explicit
$ git fetch second main next
with such a remote.second.refmap should behave the same way as
$ git fetch --refmap='+refs/heads/*:refs/remotes/second/*' second \
main next
in a repository without the refmote.second.refmap configuration. As
"git fetch --refmap=... second main next" should already work, it
would be only the matter of supplementing the command line argument
with configured default.
Then teach "git fetch" to further treat
$ git fetch --refmap='+refs/heads/*:refs/remotes/second/*' second
i.e., fetch with refmap but without specifying what exactly to
fetch, as a request to fetch their branches we build on (and nothing
else), using the refmap, in other words, the lack of "what to fetch"
in the above command line signals "git fetch" to rewrite the above to
$ git fetch --refmap='+refs/heads/*:refs/remotes/second/*' second \
main next
internally. Since we have the previous remote.X.refmap step already,
it means that with remote.second.refmap configured properly, the
user can only say
$ git fetch second
and it would do the right thing in our scenario.
Another and final step would be to teach "git remote add" to add
[remote "second"]
refmap = +refs/heads/*:refs/remotes/second/*
when you want to fetch only what you build on. I am not sure what
should trigger the decision. Your initial message said something
about shallow and sparse and an earlier review refuted one of them
(I do not recall which offhand, but probably sparse). It probably
is a good idea to start with an explicit command line option to "git
remote add --limited-fetch" in a single commit.
And then add heuristics (like "in a shallow clone, this mode is
turned on by default, but an explicit '--no-limited-fetch' can
countermand it") in another commit.
So far, we identified four distinct commits, each bite sized.
- remote.X.refmap configuration acts as if --refmap=... command
line argument was passed.
- passing refmap without saying what to fetch enumerates what their
branches we build on, and pretend as if the user listed these
branches on the command line to fetch.
- "git remote add --limited-fetch" creates remote.X.refmap instead
of remote.X.fetch as necessary.
- "git remote add" without explicit "--[no-]limited-fetch" uses
heuristics to enable it.
Or something like that, perhaps?
next prev parent reply other threads:[~2026-09-23 21:38 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 14:47 [PATCH] fetch: add config to avoid fetching every branch in shallow repo Harald Nordgren via GitGitGadget
2026-09-21 13:28 ` Phillip Wood
2026-09-21 21:45 ` Harald Nordgren
2026-09-22 13:00 ` Harald Nordgren
2026-09-22 14:53 ` Phillip Wood
2026-09-22 15:37 ` Harald Nordgren
2026-09-23 15:14 ` Phillip Wood
2026-09-22 17:11 ` Junio C Hamano
2026-09-22 21:40 ` Harald Nordgren
2026-09-23 15:19 ` Phillip Wood
2026-09-23 15:34 ` Junio C Hamano
2026-09-23 16:55 ` D. Ben Knoble
2026-09-23 19:50 ` Junio C Hamano
2026-09-24 17:10 ` D. Ben Knoble
2026-09-24 18:02 ` Junio C Hamano
2026-09-23 20:35 ` [PATCH v2] fetch: avoid fetching every branch of a new remote in a " Harald Nordgren via GitGitGadget
2026-09-23 21:38 ` Junio C Hamano [this message]
2026-09-25 10:49 ` [PATCH v3 0/4] " Harald Nordgren via GitGitGadget
2026-09-25 10:49 ` [PATCH v3 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-09-25 22:38 ` Junio C Hamano
2026-09-25 10:50 ` [PATCH v3 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-09-25 23:26 ` Junio C Hamano
2026-09-25 10:50 ` [PATCH v3 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-09-25 10:50 ` [PATCH v3 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-09-29 9:19 ` [PATCH v4 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Harald Nordgren via GitGitGadget
2026-09-29 9:19 ` [PATCH v4 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-09-29 9:19 ` [PATCH v4 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-09-29 9:27 ` Harald Nordgren
2026-09-29 20:17 ` Junio C Hamano
2026-09-29 9:19 ` [PATCH v4 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-09-29 9:19 ` [PATCH v4 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-09-29 19:36 ` [PATCH v4 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Junio C Hamano
2026-10-02 7:13 ` [PATCH v5 " Harald Nordgren via GitGitGadget
2026-10-02 7:13 ` [PATCH v5 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-02 7:13 ` [PATCH v5 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-02 7:13 ` [PATCH v5 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-02 16:28 ` Junio C Hamano
2026-10-02 7:13 ` [PATCH v5 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-10-04 8:31 ` [PATCH v6 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Harald Nordgren via GitGitGadget
2026-10-04 8:31 ` [PATCH v6 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-04 8:31 ` [PATCH v6 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-04 8:31 ` [PATCH v6 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-04 8:31 ` [PATCH v6 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-10-04 17:17 ` [PATCH v6 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Junio C Hamano
2026-10-04 19:51 ` Harald Nordgren
2026-10-05 12:17 ` Junio C Hamano
2026-10-05 18:09 ` Harald Nordgren
2026-10-07 21:56 ` [PATCH v7 " Harald Nordgren via GitGitGadget
2026-10-07 21:56 ` [PATCH v7 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-07 21:56 ` [PATCH v7 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-08 16:59 ` Junio C Hamano
2026-10-07 21:56 ` [PATCH v7 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-07 21:56 ` [PATCH v7 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7bkb7in5.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=haraldnordgren@gmail.com \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.