I don\'t see an option to checkout or list remote/local branches in this module: https://gitpython.readthedocs.io/en/stable/
I had a similar issue. In my case I only wanted to list the remote branches that are tracked locally. This worked for me:
import git
repo = git.Repo(repo_path)
branches = []
for r in repo.branches:
branches.append(r)
# check if a tracking branch exists
tb = t.tracking_branch()
if tb:
branches.append(tb)
In case all remote branches are needed, I would prefer running git directly:
def get_all_branches(path):
cmd = ['git', '-C', path, 'branch', '-a']
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return out