如何从远程 Git 仓库中仅获取分支名称?

4

如何在不获取对象的情况下获取远程引用列表(仅包括名称和提交ID)?

显然,WebUI不是答案。

我找到的只有远程HEAD的名称:

$ git remote -v show origin
* remote origin
  Fetch URL: https://git.git
  Push  URL: https://git.git
  HEAD branch: main
  Remote branch:
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    master merges with remote master

问题用词不太好,因为在 Git 中 fetch 是一个实际的子命令。 - 0xC0000022L
@0xC0000022L 我之前使用的是 git fetch --depth 1 - OwnageIsMagic
1个回答

6
您可以使用git ls-remote origin命令:
$ git ls-remote origin
670b81a890388c60b7032a4f5b879f2ece8c4558        HEAD
ebf3c04b262aa27fbb97f8a0156c2347fecafafb        refs/heads/maint
670b81a890388c60b7032a4f5b879f2ece8c4558        refs/heads/master
670b81a890388c60b7032a4f5b879f2ece8c4558        refs/heads/next
33bc620fd1829b92a6671b6bd65ee357447aa964        refs/heads/seen
2cbe4a3e125e059242544ae415ee82452eccc15b        refs/heads/todo

该命令会列出所有的引用,包括分支和标签。如果你只想要分支,可以将它限制在匹配refs/heads的内容上:git ls-remote origin | grep refs/heads


git ls-remote --heads origin - jthill
1
@bk2204 它接受 [<repository> [<refs>...]],其中 refs 是一个 glob 模式,因此不需要使用 grep。 - OwnageIsMagic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接