How to check out a branch with GitPython How to check out a branch with GitPython python python

How to check out a branch with GitPython


If the branch exists:

repo.git.checkout('branchename')

If not:

repo.git.checkout('-b', 'branchename')

Basically, with GitPython, if you know how to do it within command line, but not within the API, just use repo.git.action("your command without leading 'git' and 'action'"), example: git log --reverse => repo.git.log('--reverse')