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

Re: Tags auto fetched by "git fetch origin" but not "git fetch origin main"

From
Yukai Chou <muzimuzhi@gmail.com>
Date
Aug 29, 2024, 23:16 UTC
Message-ID
<CAEg0tHSP60oU8a2tSfTqCOiz2AOfvR46ChWPJDMF_dTVofGymg@mail.gmail.com>
In-Reply-To
<ZtDo--AY43-bPTHG@tapette.crustytoothpaste.net>
brian m. carlson <sandals@crustytoothpaste.net> 于2024年8月30日周五 05:32写道:
Show 9 quoted lines
>
> On 2024-08-28 at 23:23:57, Yukai Chou wrote:
> > In using `git fetch [<options>] [<repository> [<refspec>…]]`,
> > - when a branch is specified as <refspec>, no tags are fetched automatically;
> > - when no <refspec>s are specified, tags are fetched automatically.
>
> Yes, this is expected.  Tags are refs, and when you specify no refspec,
> you're asking for the default behaviour, which usually involves fetching
> tags.

According to the doc section CONFIGURED REMOTE-TRACKING BRANCHES [1], when no refspec is specified,

  remote.<repository>.fetch values are used as the refspecs
Then according to doc of <refspec> [2],
  Since Git version 2.20, fetching to update refs/tags/* works the same
  way as when pushing. I.e. any updates will be rejected without + in
  the refspec (or --force).

So the tags are fetched due to the + in the remote.<repository>.fetch values, are they?

> For example, if I say, `git fetch origin
> refs/heads/main:refs/heads/main`, it would be very unexpected for it to
> fetch tags as well; ... .
Actually,
  git fetch --update-head-ok origin refs/heads/main:refs/heads/main
does fetch tags "that points into the histories being fetched".
This time the refspec is given on the command line, without +.
According to the doc of CONFIGURED REMOTE-TRACKING BRANCHES [1],
  When used in this way, the remote.<repository>.fetch values do not
  have any effect in deciding what gets fetched (i.e. the values are
  not used as refspecs when the command-line lists refspecs); they
  are only used to decide where the refs that are fetched are stored
  by acting as a mapping.

[1] https://git-scm.com/docs/git-fetch#_configured_remote_tracking_branches [2] https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt-ltrefspecgt

Yukai
Previous: Junio C Hamano
Message 6 of 6 in “Tags auto fetched by "git fetch origin" but not "git fetch origin main"”
  1. Yukai ChouAug 28, 2024
  2. brian m. carlsonAug 29, 2024
  3. Junio C HamanoAug 29, 2024
  4. brian m. carlsonAug 29, 2024
  5. Junio C HamanoAug 29, 2024
  6. Yukai ChouAug 29, 2024

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.