“Updates were rejected because the tag already exists” when attempting to push in SourceTree

落爺英雄遲暮 提交于 2020-05-09 17:39:05

问题


When attempting to Push via Source Tree, I get the following error:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags origin refs/heads/master:refs/heads/master 
Pushing to https://user@github.com/repo.git
To https://user@github.com/repo.git
 = [up to date]      master -> master
...
 ! [rejected]        example_tag -> example_tag (already exists)
updating local tracking ref 'refs/remotes/origin/master'
error: failed to push some refs to 'https://user@github.com/repo.git'
hint: Updates were rejected because the tag already exists in the remote.
Completed with errors, see above

I didn't make any changes to this tag as far as I know. How can I fix this?


回答1:


You should also be able to solve this in git bash (click on "Terminal" button in the Source Tree UI). Type:

git pull --tags



回答2:


If you have not made any local changes to the tag that you want to keep, then you can remove tag that was rejected because it already exists (example_tag in this case):

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

The reason this is common in SourceTree is because the Push all tags option is set to on by default. (Another way to hide this error is to uncheck that option.)




回答3:


Uncheck push all tags at the bottom of the UI when you confirm your git push




回答4:


git pull --tags works really well but sometimes you can get an error even with this command. Example error message:

 ! [rejected]        example_tag      -> example_tag  (would clobber existing tag)

This can be solved with the command: git pull --tags -f

Source:

https://github.com/concourse/git-resource/issues/233




回答5:


Make sure you uncheck the "Push all tags" button while push.




回答6:


Yes, indeed, pull the tags first before you push --tags. Solved my problem.




回答7:


I resolve the problem on SourceTree in this way:

  1. Deleting the tag with the selection "Remove the tag from all remotes"
  2. Recreating the tag


来源:https://stackoverflow.com/questions/31929667/updates-were-rejected-because-the-tag-already-exists-when-attempting-to-push-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!