2014-10-01 88 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' 
相關問題