是否有一种方法可以从Git中的远程设备获取引用的名称,而不获取与这些引用关联的任何对象?

是否有一种方法可以从Git中的远程设备获取引用的名称,而不获取与这些引用关联的任何对象?,git,git-fetch,Git,Git Fetch,我正在编写一个脚本,用于本地回购,其中远程回购规模大、速度慢,并且有许多分支具有不同的历史。典型的用户只关心这些分支中的一小部分,因此我希望通过不从他们不使用的分支获取对象来节省带宽 为此,我希望能够从远程获取ref的名称,而不必获取与这些ref关联的实际对象。(一旦我有了所有这些引用的名称,我计划将该列表呈现给用户,并允许他们选择他们想要的分支,这样我就可以通过编程方式构建一个非常狭窄的refspec,其中只包含他们感兴趣的分支。) Git中是否有一种方法可以查询远程repo的所有ref名称(

我正在编写一个脚本,用于本地回购,其中远程回购规模大、速度慢,并且有许多分支具有不同的历史。典型的用户只关心这些分支中的一小部分,因此我希望通过不从他们不使用的分支获取对象来节省带宽

为此,我希望能够从远程获取ref的名称,而不必获取与这些ref关联的实际对象。(一旦我有了所有这些引用的名称,我计划将该列表呈现给用户,并允许他们选择他们想要的分支,这样我就可以通过编程方式构建一个非常狭窄的refspec,其中只包含他们感兴趣的分支。)


Git中是否有一种方法可以查询远程repo的所有ref名称(在本例中为几KB),而不必同时获取其所有对象(在本例中为几GB)?(FWIW,用户可能正在使用ssh或https URL。)

据我所知,
git show remote origin
git ls remote
可以在一定程度上实现这一点。你可能需要做一些额外的过滤或匹配来得到你想要的

以下为示例:

$ git remote show origin 
* remote origin
  Fetch URL: git@10.88.1.128:Test
  Push  URL: git@10.88.1.128:Test
  HEAD branch: master
  Remote branches:
    client                      tracked
    develop                     tracked
    index                       new (next fetch will store in remotes/origin)
    master                      tracked
    refs/remotes/origin/masster stale (use 'git remote prune' to remove)
    server                      tracked
    test                        tracked
  Local branches configured for 'git pull':
    masster merges with remote masster
    master  merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)
索引
分支是由其他人新创建的,不存储在本地

编辑:一个更好的例子是新创建的git存储库,只设置了远程url,没有其他内容

git ls remote

$ git init
Initialized empty Git repository in /home/erix/gitRepos/test/.git/
$ git remote add origin git@10.88.1.128:Test
$ git ls-remote origin 
215e658c07c0e667a73ec9247f0b98c90a4fe65a        HEAD
4423ed26d1a74139997ed982cf42d681ea4eb248        refs/heads/client
1c3d2c2113d04d7771a5638729528d090d9a2eae        refs/heads/develop
8277bdd3d37b9a7c02bead816efabc6849290dc1        refs/heads/index
215e658c07c0e667a73ec9247f0b98c90a4fe65a        refs/heads/master
eb26276359ae355486536a4bfe5c939a5ab96fb0        refs/heads/server
62018d80b5d279ee2cbe8175a0bde30121288045        refs/heads/test
$ git remote show origin
* remote origin
  Fetch URL: git@10.88.1.128:Test
  Push  URL: git@10.88.1.128:Test
  HEAD branch: master
  Remote branches:
    client  new (next fetch will store in remotes/origin)
    develop new (next fetch will store in remotes/origin)
    index   new (next fetch will store in remotes/origin)
    master  new (next fetch will store in remotes/origin)
    server  new (next fetch will store in remotes/origin)
    test    new (next fetch will store in remotes/origin)
git远程显示

$ git init
Initialized empty Git repository in /home/erix/gitRepos/test/.git/
$ git remote add origin git@10.88.1.128:Test
$ git ls-remote origin 
215e658c07c0e667a73ec9247f0b98c90a4fe65a        HEAD
4423ed26d1a74139997ed982cf42d681ea4eb248        refs/heads/client
1c3d2c2113d04d7771a5638729528d090d9a2eae        refs/heads/develop
8277bdd3d37b9a7c02bead816efabc6849290dc1        refs/heads/index
215e658c07c0e667a73ec9247f0b98c90a4fe65a        refs/heads/master
eb26276359ae355486536a4bfe5c939a5ab96fb0        refs/heads/server
62018d80b5d279ee2cbe8175a0bde30121288045        refs/heads/test
$ git remote show origin
* remote origin
  Fetch URL: git@10.88.1.128:Test
  Push  URL: git@10.88.1.128:Test
  HEAD branch: master
  Remote branches:
    client  new (next fetch will store in remotes/origin)
    develop new (next fetch will store in remotes/origin)
    index   new (next fetch will store in remotes/origin)
    master  new (next fetch will store in remotes/origin)
    server  new (next fetch will store in remotes/origin)
    test    new (next fetch will store in remotes/origin)

git-ls-remote
正是我想要的……谢谢!FWIW,也不需要添加遥控器来列出它;您还可以执行
git ls remotegit@10.88.1.128:测试