Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git force push tag when the tag already exists on remote

Tags:

git

git-tag

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"
like image 301
user3606175 Avatar asked Sep 12 '14 19:09

user3606175


People also ask

How do you force push tags?

So to get around that, you'll utilize the -f or --force flags. They're interchangeable; if you want something shorter, go for -f ; if you want something more explicit and easily readable for someone new to this, use -force . And then you should get a confirmation message that the force push was complete.

How do you fix updates were rejected because the tag already exists in the remote?

Right-click the tag and choose to delete it (be sure to uncheck the Remove tag from all remotes checkbox). Choose the Fetch option (Fetch and store all tags locally does not have to be enabled). You should now have that tag that was just deleted back, and attempting to Push will no longer show that error message.

Does git push send tags to remote?

Sharing TagsBy default, the git push command doesn't transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run git push origin <tagname> .


4 Answers

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

git push -f --tags
like image 107
David Dekanozishvili Avatar answered Oct 19 '22 16:10

David Dekanozishvili


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.

like image 39
user3606175 Avatar answered Oct 19 '22 15:10

user3606175


I recommend against force pushing all tags - obv. this force pushes every local tag overwrites the remotes. This can be damaging in situations with state represented with moving tags or if any such feature is added later.

To force push/overwrite the one tag you care about and not all of them.. do:

git push origin tagName -f

like image 2
TheJeff Avatar answered Oct 19 '22 15:10

TheJeff


Firstly, update the tag on your local:

git tag v0.6.0 -f
Updated tag 'v0.6.0' (was cb85425)

Then update the tag on remote:

git push origin v0.6.0 -f
Total 0 (delta 0), reused 0 (delta 0)

 + cb85425...bf17993 v0.6.0 -> v0.6.0 (forced update)
like image 1
Izabella Raulin Avatar answered Oct 19 '22 16:10

Izabella Raulin