找到 ruby-git gem 的所有 repo 分支,而不克隆整个 repo
Find all repo branches with the ruby-git gem, without cloning the whole repo
我想查看给定存储库存在哪些分支。我知道如何通过使用 ruby-git gem:
克隆完整的存储库来做到这一点
Git.clone("https://user@bitbucket.org/my_repo.git", "my_repo", :path => "/my/repos")
g = Git.open("/my/repos/my_repo")
g.branches.each do |branch|
puts branch.name
end
但是如果我的 objective 只是简单地检查存在哪些分支,那么克隆完整的存储库感觉是错误的。没有办法只克隆元数据吗?
git ls-remote --heads https://user@bitbucket.org/my_repo.git
在不克隆存储库的情况下打印远程存储库中的所有分支。请注意,为了安全起见,远程存储库可能会拒绝 git ls-remote
。
上有一个例子
Git.ls_remote('https://github.com/ruby-git/ruby-git.git') # returns a hash containing the available references of the repo.
所以你可以试试
Git.ls_remote('https://user@bitbucket.org/my_repo.git')
如果Git.ls_remote
不支持--heads
,以refs/heads/
开头的refs就是你想要的。
我想查看给定存储库存在哪些分支。我知道如何通过使用 ruby-git gem:
克隆完整的存储库来做到这一点Git.clone("https://user@bitbucket.org/my_repo.git", "my_repo", :path => "/my/repos")
g = Git.open("/my/repos/my_repo")
g.branches.each do |branch|
puts branch.name
end
但是如果我的 objective 只是简单地检查存在哪些分支,那么克隆完整的存储库感觉是错误的。没有办法只克隆元数据吗?
git ls-remote --heads https://user@bitbucket.org/my_repo.git
在不克隆存储库的情况下打印远程存储库中的所有分支。请注意,为了安全起见,远程存储库可能会拒绝 git ls-remote
。
Git.ls_remote('https://github.com/ruby-git/ruby-git.git') # returns a hash containing the available references of the repo.
所以你可以试试
Git.ls_remote('https://user@bitbucket.org/my_repo.git')
如果Git.ls_remote
不支持--heads
,以refs/heads/
开头的refs就是你想要的。