2014-10-01 105 views
8

这个问题应该涉及到:如何通过pygit2获取当前签出的Git分支名称?

但我想知道如何做到这一点通过pygit2

+1

http://www.pygit2.org/references。 html#the-head - 'repo.head'没有做你想做的事? – 2014-10-01 04:21:27

+0

你介意把它作为答案吗?我相信这也可以帮助别人:) – Drake 2014-10-01 04:52:44

回答

6

PyGit Documentation

无论这些应该工作

head = repo.lookup_reference('HEAD').resolve() 
head = repo.head 

branch_name = head.name 
9

为了让传统的 “速记” 的名字:

from pygit2 import Repository 

Repository('.').head.shorthand # 'master' 
相关问题