How to programmatically determine whether the Git checkout is a tag and if so, what is the tag name

Viewed 20253

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine whether the current checkout is a Git tag. If it is a tag, how can I determine the tag name?

One use of this technique would be automatically labeling a release (like svnversion would do with Subversion).

See my related question about programmatically detecting the Git branch.

6 Answers
Related