简体   繁体   中英

How do i get a list of branches from a github repository?

I want a list of all my branches from a repository from github. so i can do something like this.

print(branches[1])

and ill get an output of a branch name. I haven't found a straight answer on how to do this.

import subprocess

subprocess.check_output(['git', 'branch']).decode().split('\n')

Another possibility:

from pygit2 import Repository

repo = Repository(path_to_your_repo) # use '.' if you are already there
repo.branches
g = Github("key")
repo = g.get_repo("link to repo")
versions = []
for branch in repo.get_branches():
    versions.append(branch.name)

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