Git

Remove Local Git Tags that are no Longer on the Remote Repository

Git tags are utilized to point to the specific commits from the repository history that can be more important than others. Basically, developers can use them to bookmark the bug fixes and events release or save the descriptive note to a Git commit. However, sometimes developers want to delete the tags from the local repository as well as from the remote server. The “git tag -d <tag-name>” command can be used for this corresponding purpose.

This study will compile the method of deleting the local repository tags that do not exist on the GitHub remote repository.

How to Delete Git Local Tags that are no Longer on the GitHub Remote Repository?

In order to delete the local tags that do not exist on the Git remote repository, try the below procedure:

    • Navigate to the Git root directory.
    • Show the list of all existing local repository tags and remove them.
    • Execute the “git fetch –tags” command to download the GitHub remote tags into the Git local repository.
    • Lastly, verify by displaying the list of the tags.

Step 1: Redirect to Git Root Directory

Use the following command and switch to the Git root directory:

$ cd "C:\Users\nazma\Git"

 
Step 2: List Git Local Tags

Then, execute the “git tag” command to display the list of all local tags:

$ git tag

 

Step 3: Delete Local Tags

To remove all Git local tags by running the provided command:

$ git tag -l | xargs git tag -d

 
Here, the “-l” option represents the list, and “-d“ indicates the delete operation.

As you can see, all existing tags are deleted successfully:


Step 4: Fetch Remote Tags

After that, download the remote repository tags by executing the “git fetch” command:

$ git fetch --tags

 
According to the below-given output, the updated version of the remote tags is fetched successfully:


Step 5: Verify Deleted Remote Tags

Lastly, execute the “git tag” command to ensure the local tags list is updated with the remote tag list or not:

$ git tag

 
As you can see, the tag list is updated with the centralized repository successfully:


Here you have learned about the process of removing Git local repository tags that do not exist on the GitHub remote repository.

Conclusion

To delete the local tags that do not exist on the remote repository, first, navigate to the Git root directory and list the tag. Then, delete all local tags and execute the “git fetch –tags” command to fetch the remote tags into the local machine. Lastly, verify by displaying the list of the tags. This study demonstrated the easiest way to remove the Git local repository tags that do not exist on the GitHub remote repository.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.