How To Get The Latest Tag On Git

at in tips

Tags on Git are usually used to mark versions, specific points in the project’s timeline that represents a release.

Very often we need to check which was the latest or biggest version number tagged, using only git tag command it can become really tricky after a while because it returns all the tags created in numerical order.

But you can easily retrieve the latest added tag by issuing.

git describe --tags

But if for some weird reason someone created a tag out of order you will not get the biggest version number on the tag list.

In this case, we can achieve this using the external command sort and tail.

git tag | sort --version-sort | tail -n1

See Also