git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v10 3/5] fetch: infer branches to fetch from a refmap-only remote

From
Harald Nordgren <haraldnordgren@gmail.com>
Date
Oct 25, 2026, 17:27 UTC
Message-ID
<CAHwyqnUQSninG=3hcxZOXUUwEXGbA6AT7FfmL36gwa9wV3ub4g@mail.gmail.com>
In-Reply-To
<CALnO6CCJzzX1qKeX4AR-GViM4LJjKrfdj6iafVXUQZM-c2Su4A@mail.gmail.com>
Show 11 quoted lines
> > Configuring remote.<name>.refmap without remote.<name>.fetch used to
> > make a refspec-less "git fetch <name>" fail with "--refmap option is
> > only meaningful with command-line refspec(s)", since a refmap only
> > says where to put fetched refs, not what to fetch.
>
> This makes this commit sound like a fixup of [1/5], but I think it's
> actually one of the main goals of the series! Can we flip the
> justification around to say something like "we want to allow refmaps
> to do XYZ […] Incidentally, we also make sense of the case when refmap
> is configured without fetch" ? That would make the purpose clearer to
> me, at least.
Good idea.
Show 49 quoted lines
> > Make that case infer what to fetch: the local branches whose
> > @{upstream} is already on that remote. This lets a remote be
> > configured to fetch only the branches actually in use, without
> > listing them by hand in remote.<name>.fetch, and without needing to
> > touch the command line every time.
> >
> > Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> > ---
> >  Documentation/config/remote.adoc |   5 +-
> >  Documentation/fetch-options.adoc |   6 +-
> >  builtin/fetch.c                  |  75 +++++++++++++++----
> >  remote.c                         |  24 +++++++
> >  remote.h                         |   4 ++
> >  t/meson.build                    |   1 +
> >  t/t5586-fetch-refmap.sh          | 119 +++++++++++++++++++++++++++++++
> >  7 files changed, 219 insertions(+), 15 deletions(-)
> >  create mode 100755 t/t5586-fetch-refmap.sh
> >
> > diff --git a/Documentation/config/remote.adoc b/Documentation/config/remote.adoc
> > index 103eada406..7c52e443a5 100644
> > --- a/Documentation/config/remote.adoc
> > +++ b/Documentation/config/remote.adoc
> > @@ -36,7 +36,10 @@ remote.<name>.fetch::
> >  remote.<name>.refmap::
> >         The default value of the `--refmap` option for linkgit:git-fetch[1].
> >         Used to map remote refs being fetched to remote-tracking refs to
> > -       store. See the `--refmap` entry in linkgit:git-fetch[1].
> > +       store. If `remote.<name>.fetch` is not set either, a refspec-less
> > +       fetch infers what to fetch from local branches built on this
> > +       remote, instead of fetching every branch it has. See the
> > +       `--refmap` entry in linkgit:git-fetch[1].
> >
> >  remote.<name>.push::
> >         The default set of "refspec" for linkgit:git-push[1]. See
> > diff --git a/Documentation/fetch-options.adoc b/Documentation/fetch-options.adoc
> > index c2101a7b39..90b9e13ac2 100644
> > --- a/Documentation/fetch-options.adoc
> > +++ b/Documentation/fetch-options.adoc
> > @@ -245,8 +245,10 @@ endif::git-pull[]
> >         command-line arguments. See section on "Configured Remote-tracking
> >         Branches" for details.
> >  +
> > -`remote.<name>.refmap` provides the default value for this option, the
> > -same way `remote.<name>.fetch` provides the default refspecs to fetch.
> > +When a refmap is active (from `--refmap` or `remote.<name>.refmap`) but
> > +nothing to fetch is specified on the command line, nor is there a
> > +`remote.<name>.fetch`, branches from the remote that are used as the
>
> "remote-tracking branches" ??

Yes, the next version will say "remote-tracking branches from this remote that are also configured as the @{upstream} of a local branch are fetched".

Show 21 quoted lines
> > +`@{upstream}` of our local branches are fetched.
>
> The clause here is complicated ':D I found "infer what to fetch from
> local branches built on this remote" to be a bit clearer, but we
> definitely still need to get to the point, which is that
> remote-tracking branches from this remote that are also configured as
> upstreams of local branches are fetched.
>
> Now, I wonder a bit: the doc says "when a refmap is active" we do that
> "fetch remote-tracking branches that are upstream of local branches"
> [all scoped to the current remote]---but it doesn't really say how the
> refmap affects that? I mean, I imagine it's used for mapping (duh),
> but I don't know if it also narrows the scope, or if the scope is
> deliberately all remote-tracking branches that meet the requirements,
> or…?
>
> IOW, it seems to beg the question "why does the presence of a refmap
> control this if it has no effect on the set of selected branches," and
> I think the answer is partly "because we designed it that way" and
> possibly found in the mails leading up to this point, but we might
> want to try to connect the dots for folks? Idk.
I'll take a look at improving this part.
Show 40 quoted lines
> >
> >  `-t`::
> >  `--tags`::
> > diff --git a/builtin/fetch.c b/builtin/fetch.c
> > index 136a59154a..0fc1fb66d5 100644
> > --- a/builtin/fetch.c
> > +++ b/builtin/fetch.c
> > @@ -524,6 +524,8 @@ static struct ref *get_ref_map(struct remote *remote,
> >          */
> >         struct refspec *effective_refmap =
> >                 refmap.nr ? &refmap : remote ? &remote->refmap : NULL;
> > +       struct refspec inferred_rs;
> > +       int infer_from_refmap = 0;
> >
> >         /* opportunistically-updated references: */
> >         struct ref *orefs = NULL, **oref_tail = &orefs;
> > @@ -531,15 +533,32 @@ static struct ref *get_ref_map(struct remote *remote,
> >         struct hashmap existing_refs;
> >         int existing_refs_populated = 0;
> >
> > +       refspec_init_fetch(&inferred_rs, the_hash_algo);
> > +
> >         filter_prefetch_refspec(rs);
> >         if (remote)
> >                 filter_prefetch_refspec(&remote->fetch);
> >
> > +       if (!rs->nr && remote && !remote->fetch.nr &&
> > +           effective_refmap && effective_refmap->nr) {
> > +               struct string_list tracked = STRING_LIST_INIT_DUP;
> > +               struct string_list_item *item;
> > +
> > +               branches_tracking_remote(the_repository, remote, &tracked);
> > +               for_each_string_list_item(item, &tracked)
> > +                       refspec_append(&inferred_rs, item->string);
> > +               string_list_clear(&tracked, 0);
>
> Interesting choice of string_list again ;) do we need the sorting
> behavior? (In fact, since it could come from an "ordered" config,
> perhaps we should use that order?) A strvec seems more appropriate
> then…

Agreed, the next version uses a strvec here too. Nothing is sorted anymore: the branches come in refname order, and each branch's merge entries in config order.

Show 54 quoted lines
> > +
> > +               rs = &inferred_rs;
> > +               infer_from_refmap = 1;
> > +       }
> > +
> >         if (rs->nr) {
> >                 struct refspec *fetch_refspec;
> >
> >                 for (i = 0; i < rs->nr; i++) {
> > -                       get_fetch_map(remote_refs, &rs->items[i], &tail, 0);
> > +                       get_fetch_map(remote_refs, &rs->items[i], &tail,
> > +                                     infer_from_refmap);
> >                         if (rs->items[i].dst && rs->items[i].dst[0])
> >                                 *autotags = 1;
> >                 }
> > @@ -574,6 +593,8 @@ static struct ref *get_ref_map(struct remote *remote,
> >
> >                 for (i = 0; i < fetch_refspec->nr; i++)
> >                         get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
> > +       } else if (infer_from_refmap) {
> > +               /* Already fully handled above. */
> >         } else if (refmap.nr) {
> >                 die("--refmap option is only meaningful with command-line refspec(s)");
> >         } else {
> > @@ -669,6 +690,7 @@ static struct ref *get_ref_map(struct remote *remote,
> >         if (existing_refs_populated)
> >                 hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent);
> >
> > +       refspec_clear(&inferred_rs);
> >         return ref_map;
> >  }
> >
> > @@ -1978,13 +2000,47 @@ static int do_fetch(struct transport *transport,
> >
> >         if (rs->nr) {
> >                 refspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes);
> > +       } else if (transport->remote->fetch.nr) {
> > +               struct string_list tracked = STRING_LIST_INIT_DUP;
> > +               struct string_list_item *item;
> > +
> > +               refspec_ref_prefixes(&transport->remote->fetch,
> > +                                    &transport_ls_refs_options.ref_prefixes);
> > +               /*
> > +                * See remote.c's handling of remote.<name>.followRemoteHEAD
> > +                * for the analogous, still-unresolved case.
>
> Is this a "we haven't resolved what to do" case, or a "some remote (or
> something) hasn't resolved" case? I'm not sure what I should be
> looking at here.
>
> Oh, I see. It's a duplicate of comment and code from the
> else{effective_refmap->nr} block below. Hrm… probably it would be nice
> not to duplicate that? I can't spot any differences between the code
> blocks.
Yes, good idea!
Harald
Previous: D. Ben KnobleNext: Harald Nordgren via GitGitGadget
Message 101 of 154 in “fetch: add config to avoid fetching every branch in shallow repo”
  1. fetch: add config to avoid fetching every branch in shallow repoHarald Nordgren via GitGitGadget, Sep 19, 2026
  2. Phillip WoodSep 21, 2026
  3. Harald NordgrenSep 21, 2026
  4. Harald NordgrenSep 22, 2026
  5. Phillip WoodSep 22, 2026
  6. Harald NordgrenSep 22, 2026
  7. Phillip WoodSep 23, 2026
  8. Junio C HamanoSep 22, 2026
  9. Harald NordgrenSep 22, 2026
  10. Phillip WoodSep 23, 2026
  11. Junio C HamanoSep 23, 2026
  12. D. Ben KnobleSep 23, 2026
  13. Junio C HamanoSep 23, 2026
  14. D. Ben KnobleSep 24, 2026
  15. Junio C HamanoSep 24, 2026
  16. fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Sep 23, 2026
  17. Junio C HamanoSep 23, 2026
  18. 0/4 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Sep 25, 2026
  19. 1/4 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Sep 25, 2026
  20. Junio C HamanoSep 25, 2026
  21. 2/4 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Sep 25, 2026
  22. Junio C HamanoSep 25, 2026
  23. 3/4 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Sep 25, 2026
  24. 4/4 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Sep 25, 2026
  25. 0/4 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Sep 29, 2026
  26. 1/4 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Sep 29, 2026
  27. 2/4 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Sep 29, 2026
  28. Harald NordgrenSep 29, 2026
  29. Junio C HamanoSep 29, 2026
  30. 3/4 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Sep 29, 2026
  31. 4/4 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Sep 29, 2026
  32. Junio C HamanoSep 29, 2026
  33. 0/4 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 2, 2026
  34. 1/4 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 2, 2026
  35. 2/4 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 2, 2026
  36. 3/4 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 2, 2026
  37. Junio C HamanoOct 2, 2026
  38. 4/4 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 2, 2026
  39. 0/4 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 4, 2026
  40. 1/4 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 4, 2026
  41. 2/4 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 4, 2026
  42. 3/4 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 4, 2026
  43. 4/4 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 4, 2026
  44. Junio C HamanoOct 4, 2026
  45. Harald NordgrenOct 4, 2026
  46. Junio C HamanoOct 5, 2026
  47. Harald NordgrenOct 5, 2026
  48. 0/4 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 7, 2026
  49. 1/4 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 7, 2026
  50. 2/4 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 7, 2026
  51. Junio C HamanoOct 8, 2026
  52. Harald NordgrenOct 9, 2026
  53. Harald NordgrenOct 9, 2026
  54. 3/4 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 7, 2026
  55. 4/4 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 7, 2026
  56. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 10, 2026
  57. 1/5 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 10, 2026
  58. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 10, 2026
  59. Junio C HamanoOct 10, 2026
  60. Harald NordgrenOct 10, 2026
  61. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 10, 2026
  62. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 10, 2026
  63. Junio C HamanoOct 10, 2026
  64. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 10, 2026
  65. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 14, 2026
  66. 1/5 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 14, 2026
  67. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 14, 2026
  68. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 14, 2026
  69. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 14, 2026
  70. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 14, 2026
  71. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 20, 2026
  72. 1/5 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 20, 2026
  73. D. Ben KnobleOct 24, 2026
  74. Harald NordgrenOct 24, 2026
  75. D. Ben KnobleOct 25, 2026
  76. Harald NordgrenOct 25, 2026
  77. Junio C HamanoOct 25, 2026
  78. Harald NordgrenOct 26, 2026
  79. Junio C HamanoOct 26, 2026
  80. Phillip WoodOct 27, 2026
  81. Junio C HamanoOct 27, 2026
  82. Phillip WoodOct 28, 2026
  83. Junio C HamanoOct 28, 2026
  84. Harald NordgrenOct 28, 2026
  85. Phillip WoodOct 29, 2026
  86. Junio C HamanoOct 29, 2026
  87. Phillip WoodOct 26, 2026
  88. Junio C HamanoOct 26, 2026
  89. Phillip WoodOct 26, 2026
  90. Ben KnobleOct 29, 2026
  91. Harald NordgrenOct 29, 2026
  92. Junio C HamanoOct 29, 2026
  93. Harald NordgrenOct 30, 2026
  94. Notes, refs, etc. (was: Re: [PATCH v10 1/5] fetch: add remote.<name>.refmap)D. Ben Knoble, Nov 7, 2026
  95. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 20, 2026
  96. D. Ben KnobleOct 24, 2026
  97. Harald NordgrenOct 25, 2026
  98. D. Ben KnobleOct 27, 2026
  99. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 20, 2026
  100. D. Ben KnobleOct 24, 2026
  101. Harald NordgrenOct 25, 2026
  102. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 20, 2026
  103. D. Ben KnobleOct 24, 2026
  104. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 20, 2026
  105. D. Ben KnobleOct 24, 2026
  106. Harald NordgrenOct 25, 2026
  107. Junio C HamanoOct 23, 2026
  108. D. Ben KnobleOct 24, 2026
  109. Phillip WoodOct 26, 2026
  110. Junio C HamanoOct 26, 2026
  111. Harald NordgrenOct 27, 2026
  112. Phillip WoodOct 27, 2026
  113. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 25, 2026
  114. 1/5 fetch: add remote.<name>.refmapHarald Nordgren via GitGitGadget, Oct 25, 2026
  115. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 25, 2026
  116. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 25, 2026
  117. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 25, 2026
  118. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 25, 2026
  119. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 27, 2026
  120. 1/5 fetch: add remote.<name>.fetchRefmapHarald Nordgren via GitGitGadget, Oct 27, 2026
  121. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 27, 2026
  122. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 27, 2026
  123. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 27, 2026
  124. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 27, 2026
  125. 0/6 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Oct 30, 2026
  126. 1/6 fetch: add remote.<name>.fetchRefmapHarald Nordgren via GitGitGadget, Oct 30, 2026
  127. Phillip WoodNov 12, 2026
  128. Junio C HamanoNov 12, 2026
  129. Phillip WoodNov 13, 2026
  130. 2/6 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Oct 30, 2026
  131. 3/6 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Oct 30, 2026
  132. 4/6 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Oct 30, 2026
  133. 5/6 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Oct 30, 2026
  134. 6/6 remote: resolve @{push} through remote.<name>.fetchRefmapHarald Nordgren via GitGitGadget, Oct 30, 2026
  135. D. Ben KnobleNov 11, 2026
  136. Junio C HamanoNov 11, 2026
  137. Harald NordgrenNov 14, 2026
  138. Harald NordgrenNov 11, 2026
  139. Phillip WoodNov 11, 2026
  140. Junio C HamanoNov 11, 2026
  141. D. Ben KnobleNov 11, 2026
  142. Phillip WoodNov 12, 2026
  143. Matt HunterNov 12, 2026
  144. Phillip WoodNov 17, 2026
  145. 0/5 fetch: avoid fetching every branch of a new remote in a shallow repoHarald Nordgren via GitGitGadget, Nov 14, 2026
  146. 1/5 fetch: add remote.<name>.fetchRefmapHarald Nordgren via GitGitGadget, Nov 14, 2026
  147. Phillip WoodNov 17, 2026
  148. Junio C HamanoNov 17, 2026
  149. Phillip WoodNov 17, 2026
  150. Junio C HamanoNov 17, 2026
  151. 2/5 fetch: extract collect_upstream_from_remote() helperHarald Nordgren via GitGitGadget, Nov 14, 2026
  152. 3/5 fetch: infer branches to fetch from a refmap-only remoteHarald Nordgren via GitGitGadget, Nov 14, 2026
  153. 4/5 remote: add "git remote add --limited-fetch"Harald Nordgren via GitGitGadget, Nov 14, 2026
  154. 5/5 remote: default to --limited-fetch in a shallow repositoryHarald Nordgren via GitGitGadget, Nov 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.