1

这是使用 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
4

1 回答 1

0

GitPython 教程中所见,克隆将是:

from git import Repo

cloned_repo = repo.clone("<url>")
于 2020-05-02T13:28:15.447 回答