Git by Example: Tag Deletion
Learn how to remove tags from both your local repository and the remote server. This is useful for fixing mistakes or cleaning up old release candidates.
Code
# 1. Delete a tag locally
git tag -d v1.0
# Output:
# Deleted tag 'v1.0' (was 1a2b3c)
# 2. Delete a tag from the remote repository
git push origin --delete v1.0
# Output:
# To https://github.com/user/repo.git
# - [deleted] v1.0
# 3. Alternative syntax for remote deletion (older Git versions)
git push origin :refs/tags/v1.0Explanation
Sometimes you might create a tag by mistake, perhaps naming it incorrectly or tagging the wrong commit. In these cases, you need to delete the tag. Deleting a tag in Git is a two-step process if you have already pushed the tag to a remote server: you must delete it locally and then delete it remotely.
Deleting a local tag is straightforward using the -d or --delete flag. This removes the reference from your local machine. However, this does not affect the remote repository. If you pull from the remote again, the tag might come back.
To permanently remove the tag from the shared remote repository, you must execute a specific push command. The modern syntax git push origin --delete tagname is intuitive. The older syntax git push origin :refs/tags/tagname is more cryptic but works on very old Git versions; it effectively says "push nothing into the remote tag", overwriting it with null.
- Deleting locally does not delete remotely
- Use
git tag -dfor local deletion - Use
git push --deletefor remote deletion - Essential for correcting release mistakes

