How to Delete Local and Remote Tags on Git?
This manual will describe:
So, let’s start!
How to Delete Local Tags on Git?
Git Users can delete tags from both repositories and multiple tags. More specifically, the “$ git tag -l | xargs git tag -d” command is used to delete the whole tag list from the local branch. This command can be utilized to delete single, multiple, or all local tags at once.
Let’s check out the below-provided steps to understand the above-discussed scenario!
First, check the list of the existing local tags through the “git tag” command:
Method 1: Delete Single Local Tags on Git
Execute the “git tag” command with the “-d” option and specify the local tag name to delete:
As you can see the local tag “v1.0” is deleted successfully from the repository:
Method 2: Delete Multiple Local Tags on Git
To delete multiple local tags, execute the below-given command:
Here, you can see that the specified tags are deleted simultaneously:
Method 3: Delete All Local Tags on Git
Git also allows you to delete all tags at once from the repository by utilizing the “git tag -l” command:
Now, move toward the next section to delete the remote tags on Git.
How to Delete Remote Tags on Git?
While working on Git, sometimes developers push the wrong tags to the Git remote repository. In this situation, they want to revert the operation or remove the pushed tags from the remote repository. If the tag remains in the remote repository, then when the user performs the next pull request, it gets restored to the local repository. So, it is required to delete the tag from both locations.
There are two different ways to delete single or multiple remote tags on Git, such as:
- By pushing an empty tag reference to the remote
- By using the delete option
Let’s check out each of them one by one!
Method 1: Delete Remote Tags by Pushing an Empty Tag Reference
Pushing an empty reference of a remote tag using the “git push” command can let you delete the specified remote tag:
Here, the “origin” is the name of our remote repository and “:v1.0” is an empty reference of remote tag:
Method 2: Delete Single Remote Tag by Using Delete Option
Deleting a tag from the remote repository using the “–delete” option is another efficient way to perform the same operation:
Method 3: Delete Multiple Remote Tags by Using Delete Option
Git also allows users to delete multiple tags at once using the “–delete” option. To do so, execute the provided command:
Method 4: Delete All Remote Tags by Using Delete Option
To remove the remote tags list, first, run the “git fetch” command to fetch all remote tags:
Then, run the below-given command to remove all remote tags:
Here, “-l” option is added to list out the delete remote tags:
That’s all! We have provided multiple ways to remove the local and remote tags on Git.
There are multiple commands that can delete single tags, multiple tags at once, or a whole list of local and remote tags through the different available Git commands, such as “$ git tag -l | xargs git tag -d” or the “$ git push” command with the “–delete” option. This manual provided the different methods to delete local and remote tags on Git.