Are you curious to learn how to delete local & remote tags on Git? Firstly, you should gain some knowledge about tags and git tags together with Git Commands. Generally, tags are utilized to tag particular commits that may be more significant than others. Also, you can use tags for bookmarking specific events like releases, bug fixes or simply to add an informative and descriptive note to a commit.
For instance, tags are often associated with genuine product releases on GitHub. But in some situations, you may require to delete git tags locally or remotely with ease. Now, it’s time to learn completely about the process of deleting Local and Remote Tags on Git. Use these available links and learn the concept that you are eagerly waiting for.
Git tags support tagging particular points in the history of the repository and answer to them later. Once you create a tag, it won’t have a commit history. Actually, you can observe two types of tags supported by git. They are Annotated and Lightweight Tags. The major difference between them is the amount of metadata they store. One more difference is that annotated tags are public, and lightweight tags are private.
Now, you get some idea about git tags. So, take a look at the below explained delete local and remote tags in Git.
- How To Clean Up Git Branches | Git Clean Up Local and Remote Branches
- How To Checkout Git Tags | How Do You Checkout Latest Git Tag Easily?
- How To Create Git Tags | Types of Tags in Git | Creating Git Tags with Examples
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 “v1.0” on your commit list, you would run
$ git tag -d v1.0 Deleted tag 'v1.0' (was 808b598)
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 v2.0 error: tag 'v2.0' 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 <empty>
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 “v1.0”, you would run
$ git push --delete origin v1.0 To https://github.com/SCHKN/repo.git - [deleted] v1.0
To delete a remote Git tag, you can also use the “git push” command and specify the tag name using the ref’s syntax.
$ git push origin :refs/tags/<tag>
Back to the example, in order to delete a tag named “v1.0”, you would run
$ git push origin :refs/tags/v1.0 To https://github.com/SCHKN/repo.git - [deleted] v1.0
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.
In this tutorial, you have learned how you can easily delete a local and a remote Git tag. If you are interested to learn more about Git, check out our other tutorials on the subject such as: