如何使用python在git存储库中获取name当前bramch名称



这是使用ssh密钥获取git中当前分支名称的脚本

URL = raw_input('Enter the ssh git URL: ')
print URL
from pygit2 import Repository
repo = Repository(URL)
# option 1
head = repo.head
print("Head is " + head.name)
# option 2
head = repo.lookup_reference('HEAD').resolve()
print("Head is " + head.name)

错误:显示未找到存储库。请帮助获取git存储库中的当前分支机构名称

Traceback (most recent call last):
File "Clone.py", line 28, in <module>
Repository(URL).head.shorthand
File "/usr/lib/python2.7/dist-packages/pygit2/repository.py", line 1184, in __init__
path_backend = init_file_backend(path)
_pygit2.GitError: Repository not found at git@gitlab.com:Manoj.ck/sampleproject.git

如GitPython教程中所示,克隆将是:

from git import Repo
cloned_repo = repo.clone("<url>")

最新更新