I get the following error after I run the steps below:
To [email protected]:username/repo-name.git
! [rejected] dev -> dev (already exists)
error: failed to push some refs to '[email protected]:username/repo-name.git'
hint: Updates were rejected because the tag already exists in the remote.
dev
: git tag dev
git push --tags
Deleted tag dev
, created it again and pushed tags:
git tag -d dev
git tag dev
git push --tags
Why is this happening?
I am on Mac. My friends that use Linux (Ubuntu) don't have this problem. I know that I can use git push --tags -f
to force the tag update, but this is dangerous (e.g. rewriting a commit made by mistake only in the tag, not in the branch).
This question is related to
git
repository
git-tag
It's quite simple if you're using SourceTree.
Basically you just need to remove and re-add the conflicting tag:
If you want to UPDATE a tag, let's say it 1.0.0
git checkout 1.0.0
git ci -am 'modify some content'
git tag -f 1.0.0
git push origin --delete 1.0.0
git push origin 1.0.0
DONE
The reason you are getting rejected is that your tag lost sync with the remote version. This is the same behaviour with branches.
sync with the tag from the remote via git pull --rebase <repo_url> +refs/tags/<TAG>
and after you sync, you need to manage conflicts.
If you have a diftool installed (ex. meld) git mergetool meld
use it to sync remote and keep your changes.
The reason you're pulling with --rebase flag is that you want to put your work on top of the remote one so you could avoid other conflicts.
Also, what I don't understand is why would you delete the dev
tag and re-create it??? Tags are used for specifying software versions or milestones. Example of git tags v0.1dev
, v0.0.1alpha
, v2.3-cr
(cr - candidate release) and so on..
Another way you can solve this is issue a git reflog
and go to the moment you pushed the dev
tag on remote. Copy the commit id and git reset --mixed <commmit_id_from_reflog>
this way you know your tag was in sync with the remote at the moment you pushed it and no conflicts will arise.
It seems that I'm late on this issue and/or it has already been answered, but, what could be done is: (in my case, I had only one tag locally so.. I deleted the old tag and retagged it with:
git tag -d v1.0
git tag -a v1.0 -m "My commit message"
Then:
git push --tags -f
That will update all tags on remote.
Could be dangerous! Use at own risk.
Some good answers here. Especially the one by @torek. I thought I'd add this work-around with a little explanation for those in a rush.
To summarize, what happens is that when you move a tag locally, it changes the tag from a non-Null commit value to a different value. However, because git (as a default behavior) doesn't allow changing non-Null remote tags, you can't push the change.
The work-around is to delete the tag (and tick remove all remotes). Then create the same tag and push.
Source: Stackoverflow.com