Progress:
TIER 3 · MODULE 32· Expert

git ls-remote

Curl for Git remotes.

🎯 What & why

git ls-remote queries a remote's refs over the wire without fetching any objects. Like curl for Git: cheap, scriptable, and works without a working tree.

🧠 Mental model

It is a ref-discovery RPC. The remote streams back its branch and tag list with SHAs; you can filter, sort, and even resolve symbolic refs like HEAD.

🛠️ Synopsis

git ls-remote [-h] [-t] [--exit-code] [--get-url] [--symref] [--sort=<key>] <remote> [<patterns>...]

🎚️ Switches & options

FlagWhat it does
<remote>Remote name or URL (e.g., origin, https://github.com/foo/bar)
<patterns>...Glob patterns to filter refs server-side
-h, --headsOnly show branch refs (refs/heads/*)
-t, --tagsOnly show tag refs (refs/tags/*)
--exit-codeExit 2 if no matching refs found — useful in scripts
--get-urlPrint the resolved URL instead of querying; honors insteadOf
--symrefShow what HEAD (or other symrefs) points to
--sort=<key>Sort output by key (e.g., -v:refname for newest tags first)

💡 Use cases

🧪 Examples

List everything on origin
git ls-remote origin
Only branches matching a pattern
git ls-remote -h origin 'refs/heads/release/*'
Find the default branch
git ls-remote --symref origin HEAD
Newest tags first
git ls-remote -t --sort=-v:refname origin

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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