How To Delete A Remote Or Local Tag In Git?
Git tags are pointers to specific commits used to mark release versions or as bookmarks. Sometimes, however, developers might want to remove a tag from a remote server or the local repository.
To remove a local tag in Git, type:
bashgit tag -d your_tag
To remove a remote tag in Git, type:
bashgit push --delete origin your_tag
In this article, I will explain how to remove a Git tag from local and remote, how to remove multiple Git tags at once, and many more.
Let's get to it 😎.
How to delete a local tag?
In Git, to delete a local tag, you need to use the git tag -d command:
bashgit tag -d your_tag
You can verify that the tag was correctly deleted by searching the tag name with the git tag -l command:
bashgit tag -l your_tag
If the command outputs nothing, the tag was successfully deleted.
How to delete a remote tag?
In Git, to delete a remote tag, you need to use the git push command with the --delete option:
bashgit push --delete origin your_tag
However, you may have a situation where you have the same name for a branch and a tag. If you want to avoid any confusion and be sure that you are deleting a tag, use full refs like so:
bashgit push origin :refs/tags/your_tag
This command will work for remote tags.
How to delete multiple tags at once?
In Git, to delete multiple tags at once, you need to use a wildcard with two git tag commands.
First, select the tags you want to delete and put them in a variable. Then you use that variable to remove the tags.
Here is an example of this:
bashgit tag -d $(git tag -l "tag*")
How to delete tags by using a wildcard?
In Git, you can use a combination of git tag commands to delete tags by pattern.
To delete tags by a pattern on the local repository, type:
bashgit tag -d $(git tag -l "your_tag*")
To delete tags by a pattern on the remote server, type:
bashgit push -d $(git tag -l "your_tag*")
Final thoughts
As you can see, deleting a tag in Git is very easy and can be done in one command.
Here are some of my related tutorials for you (if you want to learn more about Git).