Version Strings With git describe

Build a version like v1.2-5-gabc123 for build metadata.

macOSgitcliversionLow risk
Run git describe --tags --always --dirty to print the nearest tag plus commit distance.

01Command

Command
$ git describe --tags --always --dirty

02What it does

describe turns a commit into a sortable, human-readable identifier that tells you how far past a release you are and whether the tree is dirty. It is a common input to build scripts and --version output, which is exactly the kind of metadata a terminal pipeline provides.

03Risk

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!Warning: Repositories without tags fall back to a short SHA; tag releases consistently for meaningful output.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • git-describe documentation
    Git · vendor-doc · 2026-09-20
    Evidence: Documents git describe, which names a commit from the nearest tag.

Last verified: 2026-10-13 · Category: Developer

06Related solutions