[英]How to get name current bramch name in a git repository using python
這是使用 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>")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.