public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* Tags auto fetched by "git fetch origin" but not "git fetch origin main"
@ 2024-08-28 23:23 Yukai Chou
  2024-08-29 21:32 ` brian m. carlson
  0 siblings, 1 reply; 6+ messages in thread
From: Yukai Chou @ 2024-08-28 23:23 UTC (permalink / raw)
  To: git

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.

> 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.

> <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`).

> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-29 23:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28 23:23 Tags auto fetched by "git fetch origin" but not "git fetch origin main" Yukai Chou
2024-08-29 21:32 ` brian m. carlson
2024-08-29 21:44   ` Junio C Hamano
2024-08-29 22:22     ` brian m. carlson
2024-08-29 22:38       ` Junio C Hamano
2024-08-29 23:16   ` Yukai Chou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox