Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a remote tag?

Tags:

git

git-tag

How do you delete a Git tag that has already been pushed?

like image 806
markdorison Avatar asked Mar 29 '11 23:03

markdorison


People also ask

How do I remove a commit tag?

Use Git to delete a Git tag To delete the Git tag from the local repo, run the git tag -d tag-name command where tag-name is the name of the Git tag you want to delete.

How do I delete a remote branch?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .


2 Answers

You can push an 'empty' reference to the remote tag name:

git push origin :tagname 

Or, more expressively, use the --delete option (or -d if your git version is older than 1.8.0):

git push --delete origin tagname 

Note that git has tag namespace and branch namespace so you may use the same name for a branch and for a tag. If you want to make sure that you cannot accidentally remove the branch instead of the tag, you can specify full ref which will never delete a branch:

git push origin :refs/tags/tagname 

If you also need to delete the local tag, use:

git tag --delete tagname 

Background

Pushing a branch, tag, or other ref to a remote repository involves specifying "which repo, what source, what destination?"

git push remote-repo source-ref:destination-ref 

A real world example where you push your master branch to the origin's master branch is:

git push origin refs/heads/master:refs/heads/master 

Which because of default paths, can be shortened to:

git push origin master:master 

Tags work the same way:

git push origin refs/tags/release-1.0:refs/tags/release-1.0 

Which can also be shortened to:

git push origin release-1.0:release-1.0 

By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end.

like image 50
Adam Franco Avatar answered Sep 21 '22 10:09

Adam Franco


A more straightforward way is

git push --delete origin YOUR_TAG_NAME 

IMO prefixing colon syntax is a little bit odd in this situation

like image 26
quexer Avatar answered Sep 22 '22 10:09

quexer