How to check out a branch with GitPython

后端 未结 1 498
灰色年华
灰色年华 2020-12-17 11:04

I have cloned a repository with GitPython, now I would like to checkout a branch and update the local repository\'s working tree with the contents of that branch. Ideally, I

相关标签:
1条回答
  • 2020-12-17 11:27

    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')

    0 讨论(0)
提交回复
热议问题