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

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

From
Yukai Chou <muzimuzhi@gmail.com>
Date
Aug 28, 2024, 23:23 UTC
Message-ID
<CAEg0tHRbGBBq7i78bTSfws_WZO=2W7xuDwiT2qFA5iOza8qDDA@mail.gmail.com>
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.

This reproduces with both glob (`+refs/heads/*:refs/remotes/origin/*`) or restricted (`+refs/heads/main:refs/remotes/origin/main`) `remote.<name>.fetch`.

From the git-fetch doc in Git v2.46.0 [1], I don't understand why they behave differently.

Show 5 quoted lines
> DESCRIPTION
> [...]
> By default, any tag that points into the histories being fetched is
> also fetched; the effect is to fetch tags that
> point at branches that you are interested in.
Show 5 quoted lines
> <refspec>
> [...] 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`).
Show 14 quoted lines
> CONFIGURED REMOTE-TRACKING BRANCHES
> [...]
> This configuration is used in two ways:
>
> * When `git fetch` is run without specifying what branches
> and/or tags to fetch on the command line, e.g. `git fetch origin`
> or `git fetch`, `remote.<repository>.fetch` values are used as
> the refspecs ...
>
> * When `git fetch` is run with explicit branches and/or tags
> to fetch on the command line, e.g. `git fetch origin master`, the
> <refspec>s given on the command line determine what are to be
> fetched (...). The `remote.<repository>.fetch` values determine
> which remote-tracking branch, if any, is updated.
Steps to reproduce

```shell # prepare a local upstream and fork it git init local-upstream && cd local-upstream for i in 1 2 3; do git commit --allow-empty -m "commit $i"; done git tag v0.3 cd .. git clone file://$(pwd)/local-upstream local-fork # now local-fork has all three commits and a tag v0.3

# add more commits and a new tag to upstream cd local-upstream for i in 4 5; do git commit --allow-empty -m "commit $i"; done git tag v0.5 cd ..

# try to fetch new commits and the new tag v0.5 cd local-fork # this fetches commits only git fetch origin main # this finally fetches the tag new v0.5, but why? git fetch origin cd .. ```

[1] https://git-scm.com/docs/git-fetch/2.46.0
Yukai
Next: brian m. carlson
Message 1 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.