The git ls-remote command allows you to view information about a remote Git repository without having to clone or fetch the entire repo locally. This makes it fast and lightweight to inspect a remote.
There are several useful options that provide more specific Git remote info:
View Latest Commit With --heads
The --heads option shows only the head reference, which represents the latest commit on the default branch (usually main or master):
git ls-remote --heads <remote-url>
For example:
af3e7b3b44c3f2a24c8870a0979475e36d8e6f23 refs/heads/main
This quickly retrieves the commit ID of the remote‘s current head without other refs.
Useful for checking the latest state of a repo‘s main branch.
List Tags With --tags
To view remote tags instead of heads:
git ls-remote --tags <remote-url>
Example output:
aa218f56b14c9653891f9e74264a383fa43fefbd refs/tags/v1.0
3692e9cfb74abec0f893ddd1a7ea1f016ecd5388 refs/tags/v1.1
Handy for checking if any releases or versions have been tagged in the remote repository.
Inspect Other References With --refs
The --refs option will show references beyond just heads and tags, including things like branches:
git ls-remote --refs <remote-url>
Sample output:
af3e7b3b44c3f2a24c8870a0979475e36d8e6f23 refs/heads/main
aa218f56b14c9653891f9e74264a383fa43fefbd refs/tags/v1.0
489a6ed8558908f9eab0dea1e539ff389518771c refs/remotes/origin/staging
Useful for checking refs other than HEAD or tags, like inspecting branches.
Get Remote URL With --get-url
The --get-url option simply returns the remote URL of a given alias:
git ls-remote --get-url origin
Prints out:
https://github.com/user/repo.git
Handy way to verify the remote URL configured locally.
Identify Current Branch With --symref
To identify which branch HEAD is pointing to in the remote:
git ls-remote --symref <remote-url> HEAD
Example reference result:
ref: refs/heads/main HEAD
Lets you check which branch the remote HEAD is currently referring to (main in the example above).
Conclusion
The git ls-remote command offers useful options to view specifics about a remote repo without having to clone the entire codebase. Key options include --heads, --tags, --refs, --get-url, and --symref.
Using git ls-remote can save time and disk space when you only need partial remote details. It‘s perfect for integrating into scripts and tooling workflows as well.


