首页 > 解决方案 > python中的Git命令

问题描述

我已经尝试使用下面的 python 代码从 Git 克隆存储库,但它没有克隆,它返回值为 1。

import subprocess
repo = input ("Repository:") 
_repo_ = f '{repo}'
print ("Choose local repository ") 
local = input ("Repository:") 
local_path = f '{local}'
cmd = " git clone (git repository link)"+_repo_+".git"
print(str(cmd)) 
return_value =subprocess.call(cmd, shell=True) 
print (Return value:" +str(return_value)) 

标签: pythongit

解决方案


刚找到这个库gitpython

from git import Repo

尝试

Repo.clone_from(url,repo)

或者

git.Git(PATH).clone(URL)

推荐阅读