Skip to content
Latchkey

git ls-remote: Usage, Options & Common CI Errors

git ls-remote shows the refs and their SHAs on a remote - no clone required.

ls-remote is the cheap way to check if a tag exists or what SHA a branch points to before doing real work.

What it does

git ls-remote queries a remote repository and prints its references (branches, tags) and the object names they point to, without downloading objects.

Common usage

Terminal
git ls-remote --heads origin
git ls-remote --tags origin
git ls-remote origin main
# fail if a tag is missing:
git ls-remote --exit-code --tags origin v1.2.0

Options

FlagWhat it does
--headsList branch refs only
--tagsList tag refs only
--exit-codeExit non-zero if no matching refs
--refsFilter out peeled/dereferenced tag entries
-q / --quietSuppress non-ref output

Common errors in CI

fatal: could not read Username for 'https://…' or 'Authentication failed' - a private remote needs credentials even just to list refs. Provide a token in the URL. An empty result with --exit-code returns 2, which scripts can use to branch on existence.

Related guides

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