0
0
GitHow-ToBeginner · 3 min read

How to Delete a Tag in Git: Simple Commands Explained

To delete a local Git tag, use git tag -d <tagname>. To delete a remote Git tag, use git push origin --delete <tagname>.
📐

Syntax

Here are the commands to delete tags in Git:

  • Delete local tag: git tag -d <tagname> removes the tag from your local repository.
  • Delete remote tag: git push origin --delete <tagname> removes the tag from the remote repository named origin.
bash
git tag -d <tagname>
git push origin --delete <tagname>
💻

Example

This example shows how to delete a tag named v1.0 locally and remotely.

bash
git tag -d v1.0
# Output: Deleted tag 'v1.0'

git push origin --delete v1.0
# Output: To remote repository
# - [deleted]         v1.0
Output
Deleted tag 'v1.0' To remote repository - [deleted] v1.0
⚠️

Common Pitfalls

Common mistakes when deleting tags include:

  • Trying to delete a remote tag without deleting the local tag first or vice versa.
  • Using git push origin :refs/tags/<tagname> which is an older syntax and less clear.
  • Misspelling the tag name, which causes Git to report that the tag does not exist.

Always double-check the tag name before deleting.

bash
git push origin :refs/tags/v1.0  # Older way to delete remote tag

# Recommended way:
git push origin --delete v1.0
📊

Quick Reference

ActionCommand
Delete local taggit tag -d
Delete remote taggit push origin --delete
List all tagsgit tag
Verify remote tagsgit ls-remote --tags origin

Key Takeaways

Use 'git tag -d ' to delete a tag locally.
Use 'git push origin --delete ' to delete a tag from the remote repository.
Always confirm the tag name before deleting to avoid mistakes.
Deleting a tag locally does not remove it from the remote repository.
The older syntax 'git push origin :refs/tags/' is less clear and not recommended.