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"
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.
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.
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> .
This will force push all the tags and overwrite the existing ones.
git push -f --tags
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.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With