[[!meta title="How to show the latest git tag"]] ## TL;DR If you want to show the name of the latest tag, use: git for-each-ref --sort=-taggerdate --count=1 --format '%(tag)' refs/tags ## Some background The command *git for-each-ref* is pretty useful if you want to find something in a number of commits (or tags in this case). It allows you to use variations of output and sorting methods. For example: ### Show all tags including the message git for-each-ref --format '%(refname) %(contents:subject)' refs/tags (this is btw. very similar to **git tag -n1**) ### Show all tags sorted by date, oldest first git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags ### Show all tags sorted by date, newest first git for-each-ref --sort=-taggerdate --format '%(refname)' refs/tags ### Show latest two tags git for-each-ref --count=2 --sort=-taggerdate --format '%(refname)' refs/tags ### Show latest tag with its non-ambiguous short name git for-each-ref --sort=-taggerdate --count=1 --format '%(refname:short)' refs/tags ### Show latest tag git for-each-ref --count=1 --sort=-taggerdate --format '%(tag)' refs/tags (note: this is the same as the previous one, but uses the *tag* field) [[!tag git ungleich]]