How to Delete Git Tags (Local and Remote)
Git tags are typically used to mark specific points in a repository’s history as being important, most commonly for releases (v1.0, v2.0). However, mistakes happen, and sometimes you need to remove a tag that was created in error.
Here is a quick cheat sheet for managing and deleting tags.
1. Delete a Local Tag
This removes the tag from your local machine only. It does not affect the server.
git tag -d <tag_name>
# Example:
# git tag -d v0.0.1
2. Delete a Remote Tag
This removes the tag from the remote repository (e.g., GitHub, GitLab).
git push --delete origin <tag_name>
# Example:
# git push --delete origin v0.0.1
3. Delete All Local Tags
This is useful if your local tags are completely out of sync with the remote and you want to start fresh.
git tag -d $(git tag -l)
4. Delete All Remote Tags
Warning: This is destructive and will remove every release tag from your remote repository. Use with extreme caution.
git push origin --delete $(git tag -l)
5. Fetch Remote Tags
After deleting your local tags, you often want to re-sync with the remote to get the “correct” list of tags.
git fetch --tags