git describe --tags

Shows the nearest tag name reachable from the current commit.

This command helps you quickly identify which tag your current commit is closest to, giving you an easy-to-read version label.

It works by walking back through the commit history until it finds the most recent annotated or lightweight tag, then prints that tag name; adding --long will also show how many commits you are past that tag and the abbreviated commit hash, and you can tweak the --abbrev=<n> value to control hash length or use --match <pattern> to filter which tags are considered.

Variations include --all to let it consider branch and remote names as well as tags, --long to display commit count and hash suffix, or combining --match 'v[0-9]*' to only match tags that start with “v”.

Similar commands that complement this are git tag for listing all tags, and git rev-parse HEAD for directly printing the current commit hash.

Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...