Checkout or list remote branches in GitPython

后端 未结 6 859
轮回少年
轮回少年 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 22:03

    Just to make it obvious - to get a list of remote branches from the current repo directory:

    import os, git
    
    # Create repo for current directory
    repo = git.Repo(os.getcwd())
    
    # Run "git branch -r" and collect results into array
    remote_branches = []
    for ref in repo.git.branch('-r').split('\n'):
        print ref
        remote_branches.append(ref)
    

提交回复
热议问题