我想要來自 github 的存盤庫中所有分支的串列。所以我可以做這樣的事情。
print(branches[1])
并且會得到分支名稱的輸出。我還沒有找到關于如何做到這一點的直接答案。
uj5u.com熱心網友回復:
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
uj5u.com熱心網友回復:
g = Github("key")
repo = g.get_repo("link to repo")
versions = []
for branch in repo.get_branches():
versions.append(branch.name)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/313261.html
