Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

People also ask

How do I fetch all tags from a remote?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

Does git pull fetch all tags?

git fetch fetches all branch heads (or all specified by the remote. fetch config option), all commits necessary for them, and all tags which are reachable from these branches. In most cases, all tags are reachable in this way.

Does git pull fetches all branches?

git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .

What should git pull do by default?

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD . More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch.


A simple git fetch --tags worked for me.


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/*

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

For me the following seemed to work.

git pull --tags

It's simple. Do a

git fetch --all

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

I use this with magit on kernel.org

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