Can we set a Git default to fetch all tags during a remote pull?

Git

Git Problem Overview


I currently have a git remote setup like the following:

[remote "upstream"]
    url = <redacted>
    fetch = +refs/heads/*:refs/remotes/upstream/*

When I issue git pull on branch master, all remote heads are fetched into remotes/upstream, then remotes/upstream/master is merged into master. Any tags that can be reached are also fetched at the same time, which is very convenient.

I'd like git pull to additionally fetch all tags from the remote, not just those that are directly reachable from the heads. I originally tried seting tagopt == --tags, but found this caused only tags to be fetch and thus broke everything. (Junio even says that's a horrendous misconfiguation).

Is there a way to make git pull fetch all remote tags by default, in addition to the remote heads?

Git Solutions


Solution 1 - Git

A simple git fetch --tags worked for me.

Solution 2 - Git

You should be able to accomplish this by adding a refspec for tags to your local config. Concretely:

[remote "upstream"]
    url = <redacted>
    fetch = +refs/heads/*:refs/remotes/upstream/*
    fetch = +refs/tags/*:refs/tags/*

Solution 3 - Git

The --force option is useful for refreshing the local tags. Mainly if you have floating tags:

git fetch --tags --force

The git pull option has also the --force options, and the description is the same:

> When git fetch is used with <rbranch>:<lbranch> refspec, it refuses to > update the local branch <lbranch> unless the remote branch <rbranch> > it fetches is a descendant of <lbranch>. This option overrides that > check.

but, according to the doc of --no-tags:

> By default, tags that point at objects that are downloaded from the > remote repository are fetched and stored locally.

If that default statement is not a restriction, then you can also try

git pull --force

Solution 4 - Git

For me the following seemed to work.

git pull --tags

Solution 5 - Git

It's simple. Do a

git fetch --all

Solution 6 - Git

None of the answers worked for me when remote tags were deleted - their local equivalents would still exists in the fetching/pulling repo.

I found this combination of git fetch attributes the only way to pick up on deleted tags:

git fetch --tags --prune --prune-tags

Alternatively, this can be applied to the local (or global) git configuration:

...
[remote "origin"]
	url = [gitlab url]
	fetch = +refs/heads/*:refs/remotes/origin/*
	tagopt = --tags
	prune = true
	pruneTags = true
...

Nice side effect: This will also work for git pull (I was unable to achieve this via command line attributes).

Commands to add configuration:

git config (--global) remote.origin.tagopt --tags
git config (--global) remote.origin.prune true
git config (--global) remote.origin.pruneTags true

Solution 7 - Git

I use this with magit on kernel.org

[remote "upstream"]
    url = <redacted>
    fetch = +refs/heads/*:refs/remotes/upstream/*
    tagOpt = --tags

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjleahyView Question on Stackoverflow
Solution 1 - GitrussoueView Answer on Stackoverflow
Solution 2 - GitjoshtklingView Answer on Stackoverflow
Solution 3 - GityucerView Answer on Stackoverflow
Solution 4 - GitVasantha GaneshView Answer on Stackoverflow
Solution 5 - GitamulamulView Answer on Stackoverflow
Solution 6 - GitJan GrothView Answer on Stackoverflow
Solution 7 - GiteventView Answer on Stackoverflow