tag
remote
git

How can I delete a remote tag?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

To delete a remote tag in Git, you need to follow these steps:

1. Delete the Tag Locally (Optional)

First, you can delete the tag locally using the git tag -d command. This step is optional, but it helps keep your local repository clean.

bash
git tag -d <tagname>

Replace <tagname> with the name of the tag you want to delete.

Example:

bash
git tag -d v1.0.0

2. Delete the Tag from the Remote Repository

To delete the tag from the remote repository, you can use the git push command with the :refs/tags/<tagname> syntax.

bash
git push origin :refs/tags/<tagname>

Replace <tagname> with the name of the tag you want to delete.

Example:

bash
git push origin :refs/tags/v1.0.0
  • Explanation:
    • origin: The name of the remote repository. Replace this with your remote's name if it's different.
    • :refs/tags/v1.0.0: The colon (:) before refs/tags/v1.0.0 tells Git to delete the tag on the remote.

3. Verify the Deletion

You can verify that the tag has been deleted from the remote repository by running:

bash
git ls-remote --tags origin

This command lists all tags in the remote repository, allowing you to confirm that the specified tag has been removed.

Summary

  • Delete Locally: git tag -d <tagname> (optional)
  • Delete Remotely: git push origin :refs/tags/<tagname>

This process ensures that the tag is removed both locally (if you choose to) and from the remote repository.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.