0
0
Gitdevops~5 mins

Deleting tags in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you create tags in Git that you no longer need or that were created by mistake. Deleting tags helps keep your project clean and organized by removing these unwanted markers.
When you accidentally create a tag with the wrong name and want to remove it.
When a tag points to an outdated version of your code and should no longer be used.
When cleaning up old tags that clutter your repository.
When you want to delete a tag both locally and from the remote repository.
When you want to free up tag names for reuse.
Commands
This command deletes the local tag named 'v1.0'. Use it to remove tags from your local Git repository.
Terminal
git tag -d v1.0
Expected OutputExpected
Deleted tag 'v1.0' (was 9fceb02)
-d - Deletes the specified local tag
This command deletes the tag named 'v1.0' from the remote repository named 'origin'. It tells Git to remove the tag from the server.
Terminal
git push origin :refs/tags/v1.0
Expected OutputExpected
To https://github.com/example/repo.git - [deleted] v1.0
This command lists all local tags to verify that the tag 'v1.0' has been deleted.
Terminal
git tag
Expected OutputExpected
v0.9 v1.1 v2.0
Key Concept

If you remember nothing else, remember: deleting a tag locally and deleting it remotely are two separate steps.

Common Mistakes
Deleting a tag locally but forgetting to delete it from the remote repository.
The tag will still exist on the remote and can be fetched again, causing confusion.
After deleting the local tag with 'git tag -d', also run 'git push origin :refs/tags/tagname' to remove it remotely.
Using 'git push origin --delete tagname' to delete a tag remotely.
This syntax deletes branches, not tags, so the tag remains on the remote.
Use 'git push origin :refs/tags/tagname' to delete tags on the remote.
Summary
Use 'git tag -d tagname' to delete a tag locally.
Use 'git push origin :refs/tags/tagname' to delete the tag from the remote repository.
Verify deletion by listing tags with 'git tag'.