简体   繁体   English

我需要获取git存储库的分支列表,而无需在本地计算机上克隆存储库

[英]I need to get a list of branches of a git repo without having cloned the repo on my local machine

Is it possible to get a list of the branches of a git repo hosted at bitbucket/github without having cloned it on the my machine? 是否有可能获得在bitbucket / github上托管的git repo分支的列表,而无需将其克隆到我的机器上? Does this make sense? 这有意义吗?

You can use 您可以使用

git ls-remote --heads <URL OF REMOTE REPO>

to get a list of branches in the remote repository. 获取远程存储库中的分支机构列表。

The entries will have the format <SHA> <REF NAME> , where the <REF NAME> is prefixed with refs/heads/ . 条目的格式为<SHA> <REF NAME> ,其中<REF NAME>带有refs/heads/前缀。 You can ignore this prefix (it's the full name of the branch refs, but that's not important for you in this situation). 您可以忽略此前缀(这是分支引用的全名,但是在这种情况下对您而言并不重要)。

If you need to do this often and only want to see the actual branch names (not the full ref names), you could also write a script to filter and transform the output. 如果您需要经常执行此操作,并且只想查看实际的分支名称(而不是完整的引用名称),则还可以编写脚本来过滤和转换输出。

Yes, the web interfaces have this information. 是的,Web界面具有此信息。

GitHub GitHub上

https://github.com/<user>/<repo>/branches https://github.com/<user>/<repo>/branches

Bitbucket 到位桶

https://bitbucket.org/<user>/<repo>#branches https://bitbucket.org/<user>/<repo>#branches

You can use this to list what remotes you have, and use the URL shown to identify which remotes are on bitbucket/github: 您可以使用它列出您拥有的遥控器,并使用显示的URL识别bitbucket / github上的遥控器:

git remote -v 

Then do this to list your remote branches, including information on what remote they belong to: 然后执行此操作以列出您的远程分支,包括有关它们所属的远程的信息:

git branch -r

The output will be in the form origin/master , where origin is the name of the remote. 输出将采用origin/master的形式,其中origin是遥控器的名称。

git branch -r will list the branches that you have fetched from the remote. git branch -r将列出您从远程获取的分支。 This includes remote branches that you are not yet tracking with local branches. 这包括您尚未与本地分支一起跟踪的远程分支。 However, git branch -r does not necessarily list all the branches that are actually in the remote repository, since you may not have fetched them. 但是, git branch -r不一定会列出远程存储库中实际存在的所有分支,因为您可能尚未获取它们。

It's unclear to me if that is what you want. 我不清楚这是否是您想要的。 If not, the other answers are better :) 如果没有,其他答案更好:)

您可以使用它来获取远程和本地分支以及Fetch和Push URL和HEAD分支的摘要:

git remote show origin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM