git name-rev <commit>

Shows a friendly reference name for a commit hash

This command helps map an obscure commit SHA to a more meaningful Git reference name so you can quickly see which branch or tag it belongs to when reviewing history.

It scans your local refs and finds the closest tag or branch that contains the commit, printing its name along with an offset (for example ~3) if you’re a few commits ahead.

You can restrict lookup to tags only with --tags, to branches only with --heads, filter specific refs via --refs=refs/heads/*, or make it fail when no name is found with --no-undefined. For similar needs, consider using git describe to show distances from annotated tags, git log --decorate -1 to view all refs on a commit, or git show-ref to browse ref mappings.

Welcome to GitExamples!

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