简体   繁体   中英

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? 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/ . 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.

GitHub

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

Bitbucket

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:

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.

git branch -r will list the branches that you have fetched from the remote. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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