Git force push tag when the tag already exists on remote

GitGit Tag

Git Problem Overview


I have a tag already pushed onto the remote. When another user creates the same tag and tries to push, the push will fail because the tag already exists on the remote.

But I thought if I did --f force tag push, it should work. But that is not what I see.

I think I have to do this.

 Create tag
 Push tag -> If push fails -> Delete tag on remote
                           -> push tag again.

Is this correct? Isn`t force pushing a tag supposed to take care of this?

I am using annotated tags with

 git -a v1.0 -f -m "message"

Git Solutions


Solution 1 - Git

This will force push all the tags and overwrite the existing ones.

git push -f --tags

Solution 2 - Git

In my case, remote was rejecting an force push when the tag already exists.

So, when the push was rejected, I did

git push --delete origin <tagname>

and pushed the new tag.

Please see Torek's comment to my question. There is a case when remote can reject the delete too.

Solution 3 - Git

if your getting fatal: tag 'beta' already exists error then use

git tag -a beta --force  #To create tag locally
git push -f --tags #To push your tag to the repository

Solution 4 - Git

Basically you asking how do you solve the issue with trying to push to a branch that already contains a tag you are trying to push (i.e. it fails because the tag already exists). You can either delete the tag on remote or delete the tag on local before pushing see: devconnected.com/how-to-delete-local-and-remote-tags-on-git

NB: do not use, or be careful when using

git push -f --tags

Because although this may work in some scenarios, be aware it will push ALL local tags and it is common to have stale/local-only tags created in error which should not be pushed

Solution 5 - Git

Firstly, delete that tag you want to replace in remote:

git push origin --delete <tag-name>

then push your tag to remote:

git push --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
Questionuser3606175View Question on Stackoverflow
Solution 1 - GitDavid DekanozishviliView Answer on Stackoverflow
Solution 2 - Gituser3606175View Answer on Stackoverflow
Solution 3 - GithashanmpView Answer on Stackoverflow
Solution 4 - GitSteven Mark FordView Answer on Stackoverflow
Solution 5 - GitYates ZhouView Answer on Stackoverflow