Progress:
TIER 3 · MODULE 41· Expert

git show-ref

for-each-ref's older, simpler sibling.

🎯 What & why

git show-ref lists refs (branches, tags, HEAD) with their SHAs. It's the older, simpler sibling of for-each-ref.

🧠 Mental model

Walks .git/refs and packed-refs, prints '<sha> <refname>' lines. No format string, no sorting, no fancy filters - just refs and hashes.

🛠️ Synopsis

git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference]
             [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [<pattern>...]
git show-ref --exists <ref>

🎚️ Switches & options

FlagWhat it does
--headInclude HEAD in the listing.
--headsLimit to refs/heads/* (local branches).
--tagsLimit to refs/tags/*.
-d, --dereferenceFor annotated tags, also show the dereferenced commit as <ref>^{}.
-s, --hash[=<n>]Print only the SHA (optionally abbreviated).
--abbrev[=<n>]Abbreviate the SHA to <n> hex chars.
--verifyStrict mode: arg must be a full ref (refs/...); fail otherwise.
-q, --quietNo output; exit code only - useful with --verify or --exists.

📦 Subcommands

--exists — Test whether a ref exists without dereferencing.
git show-ref --exists refs/heads/main

💡 Use cases

🧪 Examples

List everything plus HEAD
git show-ref --head
Just the tag SHAs (abbreviated)
git show-ref --tags --hash=12
Verify a branch exists, silently
git show-ref --verify --quiet refs/heads/main
Resolve annotated tags to commits
git show-ref -d --tags

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.