【问题标题】:How do i get a list of branches from a github repository?如何从 github 存储库中获取分支列表?
【发布时间】:2021-10-10 00:31:07
【问题描述】:

我想要一个来自 github 存储库的所有分支的列表。所以我可以做这样的事情。

print(branches[1])

并且会得到分支名称的输出。我还没有找到关于如何做到这一点的直接答案。

【问题讨论】:

    标签: python github


    【解决方案1】:
    import subprocess
    
    subprocess.check_output(['git', 'branch']).decode().split('\n')
    

    另一种可能性:

    from pygit2 import Repository
    
    repo = Repository(path_to_your_repo) # use '.' if you are already there
    repo.branches
    

    【讨论】:

      【解决方案2】:
      g = Github("key")
      repo = g.get_repo("link to repo")
      versions = []
      for branch in repo.get_branches():
          versions.append(branch.name)
      

      【讨论】:

        猜你喜欢
        • 2015-03-10
        • 1970-01-01
        • 2016-02-13
        • 2014-09-15
        • 2019-12-26
        • 2011-11-19
        • 2020-03-16
        • 2023-02-14
        • 2017-04-03
        相关资源
        最近更新 更多