Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update local tags to match remote?

Tags:

git

tags

I fixed it for my repo by deleting the local tag and then doing a git fetch. This brought the updated tag.

Is there are "right" way to update tags that may have changed on the remote? This is a simple tag, not signed or anything, created with "git tag "

like image 758
donatello Avatar asked Dec 08 '11 14:12

donatello


People also ask

How do you update a remote tag?

This could arise out of you having a situation where a tag already exists remotely, but you want to update it without deleting it. That's right: one way to replace a remote tag is to actually delete the remote (and existing) one and then push your tag to the remote repository.

How do I push local tags to remote?

This process is just like sharing remote branches — you can run git push origin <tagname> . If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command. This will transfer all of your tags to the remote server that are not already there.


4 Answers

Make sure you fetch all the tags (through git fetch --tags), to get all the tags and not just ones referencing commits reachable from the branch heads.

Those (fetched) tags are annotated ones (and usually not lightweight), and if you add deleted one on the local repo, they will just pop back after the fetch.

However, if you have deleted a lightweight one, then you need to recreate it locally: a lightweight tag isn't usually pushed or fetched to/from a remote repo.

Note that starting git 1.9/2.0 (Q1 2014), git fetch --tags will fetch everything (like git fetch), plus the tags. See "Does “git fetch --tags” include “git fetch”?".

Again, fetch "everything" means annotated and lightweight (if those lightweight tags were previously pushed).


As noted below in biocyberman's answer, if you want to fetch tags from all remotes (not just the default remote named 'origin'), you need to add the --all option.

git fetch --tags --all
like image 180
VonC Avatar answered Oct 08 '22 06:10

VonC


Previous to git 2.30, the right way seemed to be:

  git fetch origin --tags --force

You should avoid to have a branch with the same tag name, because the checkout prioritizes the branch and you can feel like the tag was not updated. Maybe git should have a warning in this case, something like:

You have updated a tag that differs now from a branch of the same name. The reference to "tagname" became ambiguous.

like image 22
yucer Avatar answered Oct 08 '22 05:10

yucer


What you have said is the right way and that is what the git tag manual recommends ( actually, it says, don't change the tags on the remote repo unless the world is coming to an end):

git tag -d X
git fetch origin tag X
like image 38
manojlds Avatar answered Oct 08 '22 05:10

manojlds


In case one has multiple upstreams:

git --version
git version 2.11.1 
git fetch --tags --all

without the --all option, I could not fetch the tags from the upstream whose name is not "upstream".

like image 3
biocyberman Avatar answered Oct 08 '22 04:10

biocyberman