Delete all tags from a Git repository

Solution 1:

git tag | xargs git tag -d

Simply follow the Unix philosophy where you pipe everything.

On Windows use git bash with the same command.

Solution 2:

To delete remote tags (before deleting local tags) simply do:

git tag -l | xargs -n 1 git push --delete origin

and then delete the local copies:

git tag | xargs git tag -d

Solution 3:

It may be more efficient to push delete all the tags in one command. Especially if you have several hundred.

In a suitable non-windows shell, delete all remote tags:

git tag | xargs -L 1 | xargs git push origin --delete

Then delete all local tags:

git tag | xargs -L 1 | xargs git tag --delete

This should be OK as long as you don't have a ' in your tag names. For that, the following commands should be OK.

git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git push origin --delete
git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git tag --delete

Other ways of taking a list of lines, wrapping them in quotes, making them a single line and then passing that line to a command probably exist. Considering this is the ultimate cat skinning environment and all.

Solution 4:

For Windows users using PowerShell:

git tag | foreach-object -process { git tag -d $_ }

This deletes all tags returned by git tag by executing git tag -d for each line returned.

Solution 5:

If you don't have the tags in your local repo, you can delete remote tags without have to take it to your local repo.

git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete

Don't forget to replace "origin" to your remote handler name.