Checkout or list remote branches in GitPython

后端 未结 6 861
轮回少年
轮回少年 2020-12-18 21:29

I don\'t see an option to checkout or list remote/local branches in this module: https://gitpython.readthedocs.io/en/stable/

6条回答
  •  感情败类
    2020-12-18 21:49

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

    in this case https://stackoverflow.com/a/47872315/12550269

    So I try this command:

    repo = git.Repo()
    
    repo.git.checkout('-b', local_branch, remote_branch)
    

    this command can make a new local branch name local_branch(if already haved, rasie error) and set up to track remote branch remote_branch

    it works very well!

提交回复
热议问题