Git tags cheat sheet

Aug 26, 2021 · Follow on Twitter and Mastodon git

In this post, let’s look at some git commands that I find useful. The post is primarily meant for future reference for myself, but can hopefully be useful to others as well.

Throughout the article, <PARAM> indicates where you should inject parameters.

List local tags with a certain name prefix/suffix

This command lists local tags with a certain name prefix or suffix:

git tag -l "<PREFIX>*"
git tag -l "*-<SUFFIX>"

List remote tags with a certain name prefix/suffix

This command lists remote tags with a certain name prefix or suffix:

git ls-remote --tags <REMOTE> | grep "<PREFIX>-.*[^}]$" | cut -f 2
git ls-remote --tags <REMOTE> | grep "\<SUFFIX>.*[^}]$" | cut -f 2

Delete local tags with a certain name prefix/suffix

This command deletes local tags with a certain name prefix or suffix:

git tag -d $(git tag -l "PREFIX-*") 
git tag -d $(git tag -l "*-<SUFFIX>")

Delete remote tags with a certain name prefix/suffix

This command deletes remote tags with a certain name prefix or suffix:

git push <REMOTE> --delete $(git ls-remote --tags <REMOTE> | grep "<PREFIX>.*[^}]$" | cut -f 2)
git push <REMOTE> --delete $(git ls-remote --tags <REMOTE> | grep "\<SUFFIX>$" | cut -f 2)

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon.

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.