As I was experimenting with git tags, I ended up with a bunch of them that I didn’t need and I wanted to remove them all. One things to keep in mind is that tags similarly to branches can be local or remote. If you create tags but don’t push them then they’re just local and you can remove them using git tag -d tagname. You do need to specify the exact tag name to do that which you can get by listing all available tags with git tag. But removing them one by one can be tedious so you can combine the two mentioned commands into the following one-liner.

git tag -d $(git tag)

But in case you have pushed the tags to the remote repository, you need to remove them from there as well. To do that you can use the git push origin --delete tagname command. Which you can also combine with the git tag to get this one-liner.

git push origin --delete $(git tag)

But if you want to remove all the tags from the local and remote repository the order is important. First, you need to remove the remote tags and then the local ones. It’s obvious if you think about it because if you remove the local tags first and then try to remove the remote ones the git tag command will return empty list so no tags will be removed from the remote repository.

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