Git Remove Local and Remote Tag : The Final Guide

On Git, tags are often used in order to tag specific commits that may be more important than others.

Tags may be used in order to bookmark certain events : releases, bug-fixes or just to add an informative and descriptive note to a commit.

On GitHub,…


This content originally appeared on DEV Community and was authored by ZigRazor

On Git, tags are often used in order to tag specific commits that may be more important than others.

Tags may be used in order to bookmark certain events : releases, bug-fixes or just to add an informative and descriptive note to a commit.

On GitHub, tags are often associated with actual product releases for example.

However, in some cases, you may want to delete Git tags easily locally or remotely.

Delete a local Git tag

In order to delete a local Git tag, use the git tag command with the -d option.

git tag -d <tag_name>

For example, if you wanted to delete a local tag named “v0.1” on your commit list, you would run

git tag -d v0.1

The output will be:

Deleted tag 'v0.1' (was 88f2a35)

If you try to delete a Git tag that does not exist, you will simply be notified that the tag does not exist.

git tag -d v0.2

the output will be:

error: tag 'v0.2' not found.

If you want to make sure that tags were correctly deleted, simply list your existing tags using the tag command and the -l option.

git tag -l

Delete a remote Git tag

In order to delete a remote Git tag, use the git push command with the -–delete option and specify the tag name.

git push --delete origin <tagname>

Back to the previous example, if you want to delete the remote Git tag named “v0.1”, you would run

git push --delete origin v0.1

the output will be:

To https://github.com/ZigRazor/repo.git
 - [deleted]         v0.1

To delete a remote Git tag, you can also use the git push command and specify the tag name using the refs syntax.

git push origin :refs/tags/<tag>

Back to the example, in order to delete a tag named “v0.1”, you would run

git push origin :refs/tags/v0.1

the output will be:

To https://github.com/ZigRazor/repo.git
 - [deleted]         v0.1

Why should we specify the “refs/tags” instead of just specifying the tagname?

In some cases, your tag may have the same name as your branch.

If you tried to delete your Git tag without specifying the “refs/tags” you would get the following error

git push origin :v1.0
error: dst refspec v1.0 matches more than one.
error: failed to push some refs to '<repository>'

As a consequence, you need to specify that you are actually trying to delete a Git tag and not a Git repository.

Conclusion

In this tutorial, you learnt how you can easily delete a local and a remote Git tag.

For More "The Final Guide" see the Index Page


This content originally appeared on DEV Community and was authored by ZigRazor


Print Share Comment Cite Upload Translate Updates
APA

ZigRazor | Sciencx (2021-08-30T10:27:46+00:00) Git Remove Local and Remote Tag : The Final Guide. Retrieved from https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/

MLA
" » Git Remove Local and Remote Tag : The Final Guide." ZigRazor | Sciencx - Monday August 30, 2021, https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/
HARVARD
ZigRazor | Sciencx Monday August 30, 2021 » Git Remove Local and Remote Tag : The Final Guide., viewed ,<https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/>
VANCOUVER
ZigRazor | Sciencx - » Git Remove Local and Remote Tag : The Final Guide. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/
CHICAGO
" » Git Remove Local and Remote Tag : The Final Guide." ZigRazor | Sciencx - Accessed . https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/
IEEE
" » Git Remove Local and Remote Tag : The Final Guide." ZigRazor | Sciencx [Online]. Available: https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/. [Accessed: ]
rf:citation
» Git Remove Local and Remote Tag : The Final Guide | ZigRazor | Sciencx | https://www.scien.cx/2021/08/30/git-remove-local-and-remote-tag-the-final-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.