← 返回命令列表

Linux command

git-ls-remote 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

List remote refs

git ls-remote [origin]

Show only tags

git ls-remote --tags [origin]

Show only heads

git ls-remote --heads [origin]

Show specific ref

git ls-remote [origin] [refs/heads/main]

List refs for URL

git ls-remote [https://github.com/owner/repo.git]

说明

git ls-remote lists references in a remote repository without downloading any objects. It shows branches, tags, and their commit hashes, useful for checking remote state before fetching. The command queries the remote directly, showing current refs at query time. This enables checking tag existence, verifying branch status, or scripting against remote repository state. It works with both named remotes and direct URLs.

参数

--heads
Show only heads (branches).
--tags
Show only tags.
--refs
Show refs only, no peeled tags.
--get-url
Show remote URL.
--exit-code
Exit with error if no refs found.
--help
Display help information.

FAQ

What is the git-ls-remote command used for?

git ls-remote lists references in a remote repository without downloading any objects. It shows branches, tags, and their commit hashes, useful for checking remote state before fetching. The command queries the remote directly, showing current refs at query time. This enables checking tag existence, verifying branch status, or scripting against remote repository state. It works with both named remotes and direct URLs.

How do I run a basic git-ls-remote example?

Run `git ls-remote [origin]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --heads do in git-ls-remote?

Show only heads (branches).