How to Delete a Remote Tag in Git

Avatar

By squashlabs, Last Updated: October 27, 2023

How to Delete a Remote Tag in Git

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

Step 1: List the existing tags

Before deleting a remote tag, it is a good practice to list all the existing tags. You can use the following command to list all the tags in your Git repository:

git tag

This command will display a list of all the tags in your repository.

Step 2: Delete the tag locally

To delete a tag locally, you can use the following command:

git tag -d <tag_name>

Replace <tag_name> with the name of the tag you want to delete. For example, to delete a tag named “v1.0.0”, you would run:

git tag -d v1.0.0

A better way to build and deploy Web Apps

  Cloud Dev Environments
  Test/QA enviroments
  Staging

One-click preview environments for each branch of code.

Step 3: Push the deletion to the remote repository

After deleting the tag locally, you need to push the deletion to the remote repository. Use the following command:

git push origin :refs/tags/<tag_name>

Replace <tag_name> with the name of the tag you want to delete. For example, to delete a tag named “v1.0.0” on the remote repository, you would run:

git push origin :refs/tags/v1.0.0

This command will delete the tag on the remote repository.

Alternative method: Using the –delete option

Another way to delete a remote tag is by using the --delete option with the git push command. This method is more straightforward and can be used as an alternative to Step 3. Here’s how you can do it:

git push --delete origin <tag_name>

Replace <tag_name> with the name of the tag you want to delete. For example, to delete a tag named “v1.0.0” on the remote repository, you would run:

git push --delete origin v1.0.0

This command will also delete the tag on the remote repository.

Best practices

When deleting a remote tag, it is important to follow these best practices:

1. Double-check the tag name: Before deleting a tag, make sure you have the correct tag name. Deleting the wrong tag can cause problems, especially if the tag is being used by other developers or in a production environment.

2. Communicate with your team: If you are working in a team, it is essential to communicate with your team members before deleting a remote tag. Inform them about the deletion and make sure it won’t cause any issues or conflicts.

3. Document the deletion: If the tag deletion is significant or affects the project’s history, consider documenting it in the project’s documentation or version control system. This will help other developers understand why the tag was deleted and prevent confusion in the future.

4. Consider creating backups: If the tag being deleted contains important information or represents a significant milestone in your project, consider creating backups or making a copy of the tag before deleting it. This can help you restore the tag if needed.

5. Perform tests after deletion: After deleting a remote tag, it is a good practice to perform tests to ensure that the deletion didn’t introduce any issues or break the project’s functionality. Test your project thoroughly before continuing with further development.

More Articles from the Git Tutorial: From Basics to Advanced Concepts series: