| by Arround The Web | No comments

How to Delete Local and Remote Tags on Git?

On Git, tags are most commonly used to bookmark the specific release version of a project and events or add descriptive and informative notes to repository commits. These mark points can easily be fetched in the future whenever the developer needs them. Git tags can be local when used on a local machine, or the developer can push them to the remote repository. However, there can be a case where developers don’t require those tags anymore. In such a situation, Git permits the developers 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:

$ git tag

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:

$ git tag -d v1.0

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:

$ git tag -d v1.0 v2.0 v2.1

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:

$ git tag -l | xargs git tag -d

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:

$ git push origin :v1.0

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:

$ git push --delete origin v1.0

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:

$ git push --delete origin v1.0 v2.0 v2.1

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:

$ git fetch

Then, run the below-given command to remove all remote tags:

$ git push origin --delete $(git tag -l)

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.

Conclusion

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.

Share Button

Source: linuxhint.com

Leave a Reply