import git
repo = git.Repo(yourRepoPath)
remote_branches = []
for ref in repo.git.branch('-r').split('\n'):
print ref
remote_branches.append(ref)
类似git命令:repo.git.action(‘不包含git 和 action 的命令’)
- git branch -r (获取所有远程分支)
repo.git.branch('-r')
- git checkout develop (切换到develop分支)
repo.git.checkout('develop')