2016-10-04 105 views
0

我找克隆在python回购如何使用python克隆git repo?

clone_start=`date +%s%N` && git clone --quiet ssh://[email protected]$host:29418/git_performance_check >& /dev/null && c 
lone_end=`date +%s%N` 
     Time_clone=`echo "scale=2;($clone_end - $clone_start)/1000000000" | bc` 

我怎样才能做到这一点相当的方式吗?

回答

2

您可以从现有资源库使用GitPyhton LIB

复制或初始化新的空的:

import git 
host = 'github' 
user = 'root' 
git.Git().clone("ssh://{0}@{1}:29418/git_performance_check".format(user, host)) 
+0

$ USER $和主机将工作,因为它是什么? – devops

+0

不,我刚编辑 –

+0

它会做安静的克隆吗? – devops

1

你可以使用GitPython。事情是这样的:

from git import Repo 

    repo = Repo.init('/tmp/git_performance_check') 
    repo.create_remote('origin', url='ssh://[email protected]:29418/git_performance_check') 
    repo.remotes.origin.fetch() 
+1

谢谢,我如何生成SSH密钥和克隆Git回购?到目前为止我找不到方法 – devops

1

这是简单和直接的方法:

import os 
os.chdir(path/where/you/need/to/store/your/project) 
os.system("your/git/repository.git") 
相关问题