get list of git branches for a repo hosted on github

放肆的年华 提交于 2019-12-08 21:55:02

问题


Is there a command line way of getting the list of branches available in a repo hosted in GITHUB (without creating and running commands from within a clone)?

I tried using curl on the url that shows the branches list and getting the content.


回答1:


git ls-remote --heads <repo-url>

Man page of git ls-remote.

For example, to git the branches of git's git repo use

$git ls-remote --heads git://github.com/git/git.git      
121f71f0da1bc9a4e1e96be2c3e683191a82a354    refs/heads/maint
f623ca1cae600e97cb0b38131fdd33e4fb669cf8    refs/heads/master
8e148144574e6c6511b591286e44a677a260d760    refs/heads/next
fcdb578342aeaf355c296026af08093b20aab9b4    refs/heads/pu
5321cb29c8f709669c5e4a04f502cd984623592c    refs/heads/todo



回答2:


Using the GitHub API:
Send a GET HTTP request to
https://api.github.com/repos/username/reponame/branches
The reply should be an array of objects, which have the name attribute being the branch name.

Source:
https://developer.github.com/v3/repos/#list-branches



来源:https://stackoverflow.com/questions/10911923/get-list-of-git-branches-for-a-repo-hosted-on-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!