-1

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.

william
  • 55
  • 7

2 Answers2

0
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
tzinie
  • 717
  • 5
  • 9
0
g = Github("key")
repo = g.get_repo("link to repo")
versions = []
for branch in repo.get_branches():
    versions.append(branch.name)
william
  • 55
  • 7