python - 如何从 github 存储库中获取分支列表?
问题描述
我想要一个来自 github 存储库的所有分支的列表。所以我可以做这样的事情。
print(branches[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
推荐阅读
- sockets - 在“接收”它们之后将 UDP 数据包保留在 OS 缓冲区中
- node.js - Mailchimp 和 Node.js 与 typescript noob 问题:Import vs Require
- symfony - symfony 4.4 + sonata deprecations like sonata.deprecated_text.twig.extension | sonata.twig.deprecated_template_extension
- java - 如何从返回 CompletableFuture 的 REST API 端点获取数据
- asp.net-core - 为什么 DotNet Core 中的 Kestrel 诞生了,尽管我们在 InProcess 模式下速度更快?
- docker - 使用 docker-compose 生成 Docker 容器时无法访问
- rust - 为什么特征没有实现?
- c# - C# iot 设备客户端中的“SetCertificatePath”选项
- r - 倾斜比例上的 betareg 导致高预测均值
- kubernetes - 从 Prometheus helm 图表向 slack 发送警报