Skip to content
Latchkey

git show-ref: Usage, Options & Common CI Errors

git show-ref lists references with their SHAs and can confirm a specific ref exists.

show-ref is the scriptable way to ask "does this branch/tag exist and what does it point to?" without parsing branch or tag output - its --verify mode is a clean CI existence gate.

What it does

git show-ref prints each matching reference as "<sha> <refname>". With --verify it checks one exact ref and exits non-zero if it is missing, making it a reliable presence test.

Common usage

Terminal
git show-ref
git show-ref --tags
git show-ref --heads
git show-ref --verify --quiet refs/heads/main && echo "exists"
git show-ref refs/tags/v1.2.0

Options

FlagWhat it does
--verifyRequire an exact, full refname
--heads / --tagsLimit to branches / tags
-q / --quietNo output; rely on exit code
--hashPrint only the object id
-d / --dereferenceAlso show what tags dereference to

Common errors in CI

fatal: ‘<ref>’ - not a valid ref - with --verify you must pass the full path (refs/heads/main, not main). A missing ref simply exits non-zero with --quiet, which is the intended gate signal. Shallow/single-branch clones may legitimately lack the ref you are checking.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →