python - 如何结帐分行
问题描述
我让 gitpython 工作来克隆一个 repo,现在我需要检查该 repo 中的分支我一直在查看文档但似乎找不到它
import git
import os
import shutil
DIR_NAME = "temp"
REMOTE_URL = "<REPO>"
if os.path.isdir(DIR_NAME):
shutil.rmtree(DIR_NAME)
os.mkdir(DIR_NAME)
repo = git.Repo.init(DIR_NAME)
origin = repo.create_remote('origin', REMOTE_URL)
origin.fetch()
origin.pull(origin.refs[0].remote_head)
解决方案
repo.git.checkout('branchename')
或者,如果分支尚不存在..
repo.git.checkout('-b', 'branchename')
推荐阅读
- raspbian - Intel Realsense:时间超出双 32 位范围
- java - 在 VS Code 中执行 Java 时未解决的编译问题
- javascript - Cookie 还是本地存储?
- spring-boot - 自动从 PCF 下载或备份生成的文件
- selenium - 无法使用 Actions 类在 Chrome 浏览器中执行鼠标悬停
- html - Angular 材料在一个组件中起作用,但在另一个组件中不起作用
- reactjs - 如何在反应组件中呈现数据库中保存的标签?
- php - 我可以在函数中使用 STDistance 吗?
- java - 如何将默认的 .ivy2 缓存目录更改为其他目录?
- gitignore - VS 2019 中的 C# .NET Framework 4.7.2 - 保留我的 clientID 和客户端机密/gitignore/Key Vault