![](/img/trans.png)
[英]How to clone master and checkout another branch in pygit2 without detached HEAD
[英]How do you checkout a branch with pygit2?
我想使用pygit2
来检查分支名称。
例如,如果我有两个分支: master
和new
, HEAD
是master
,我希望能够做到:
import pygit2
repository = pygit2.Repository('.git')
repository.checkout('new')
甚至
import pygit2
repository = pygit2.Repository('.git')
repository.lookup_branch('new').checkout()
但既不起作用,pygit2文档也没有提到如何签出分支。
看来你可以这样做:
import pygit2
repo = pygit2.Repository('.git')
branch = repo.lookup_branch('new')
ref = repo.lookup_reference(branch.name)
repo.checkout(ref)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.