By admin , 29 April 2026

Synopsis

git describe [--tags] [--always] [--dirty] [<commit>]

Description

The git describe command produces a human-readable name for a commit based on the most recent reachable tag. The output looks like v1.4.2-13-gabc1234, meaning "13 commits past tag v1.4.2, at SHA abc1234." If the commit is exactly at a tag, only the tag name is printed.

Build systems use git describe to embed version strings into binaries. With --dirty, the output includes a -dirty suffix when the working tree has uncommitted changes — perfect for marking development builds.

In day-to-day use, git describe integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git describe --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git describe interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git describe's side effects helps avoid all three.

Common Options

OptionDescription
--tagsUse lightweight tags as well as annotated.
--alwaysFall back to abbreviated SHA if no tag is reachable.
--dirty[=<mark>]Append a marker if the working tree is dirty.
--longAlways show the long format, even when at a tag.
--match <pattern>Only consider tags matching a glob.
--abbrev=<n>Use n hex digits for the SHA.
--containsShow the earliest tag that contains the commit.

Examples

git describe
# e.g. v2.1.0-3-g1a2b3c4

git describe --tags --dirty --always
# Robust version string for build scripts

git describe --match 'v[0-9]*'
# Only consider semver-style tags

git describe --contains abc123
# Find the first release that includes a commit

Common Mistakes

If your repo has only lightweight (non-annotated) tags, plain git describe says "fatal: No names found." Use --tags. Shallow clones may have no reachable tags at all — fetch tags explicitly with git fetch --tags.

Related Commands

git tag, git log, git rev-parse, git show