Just Learn Code

Mastering Git: How to Easily Delete Local and Remote Tags

Deleting Local Tags in Git

Are you new to Git and wondering how to delete a local tag? Worry not! With the right knowledge, you can delete local tags without any hassle.

Using Git tag -d to Delete Local Tags

Deleting a local tag in Git is easy using the command git tag -d. The syntax is quite simple; all you need to do is add the tag name to delete.

Here’s an example:

$ git tag -d my_tag

Before executing git tag -d, ensure that you are within the Git repository directory. If the tag is successfully deleted, you will receive a message – Deleted tag ‘my_tag’.

However, if the tag does not exist or you mistyped the tag name, you will receive an error message.

Error Message When Trying to Delete a Non-existent Tag

If you try to delete a tag that doesn’t exist, you will receive the following error message:

$ git tag -d my_non-existent_tag

error: tag ‘my_non-existent_tag’ not found.

Checking for Deletion of Tags by Listing Existing Tags

To ensure the tag is deleted, run git tag. If the tag has been deleted, it will not appear on the list.

$ git tag




In this example, my_tag is not listed, so it’s safe to say that it has been deleted successfully.

Deleting Remote Tags in Git

To delete remote tags, you need to use the git push –delete command. Here’s how to delete remote tags in Git.

Using Git Push –Delete to Delete Remote Tags

Deleting remote tags is different from deleting local tags. That’s because you need to push the changes you made to the remote repository.

Here’s the syntax for deleting remote tags:

$ git push origin –delete my_remote_tag

In this example, we are deleting a tag called my_remote_tag from the origin remote repository.

Using Refs Syntax When Tag Name Conflicts with Branch Name

If the tag name you are trying to delete conflicts with the branch name, you need to use the refs syntax by prefixing the tag name with refs/tags/. Here’s an example:

$ git push origin –delete refs/tags/my_branch_name

This command deletes my_branch_name tag located under refs/tags, thus avoiding any conflicts with the branch name.


There you have it! Deleting local and remote tags in Git is easy and can be done with just a few commands. Remember to always double-check the tag name before executing a command to avoid mistakenly deleting tags.

Happy coding!

In summary, deleting local and remote tags in Git is a simple process that can be accomplished with a few commands. For local tags, use the git tag -d command, and for remote tags, use git push –delete.

It is crucial to double-check the tag name before executing any command to avoid mistakenly deleting tags. The use of refs syntax can help avoid conflicts when the tag name conflicts with the branch name.

By following the steps provided in this article, you can easily manage your Git repository and keep it organized. Remember to be cautious and attentive to details.

Popular Posts