Chakkara
Chakkara

Reputation: 25

Git Commands in python

I have tried the below python code to clone the repository from Git but it is not cloning and it is returning the value as 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)) 

Upvotes: 0

Views: 1858

Answers (2)

Sreevardhan Reddy
Sreevardhan Reddy

Reputation: 731

you could simply do this

import subprocess

repo = input("Repository:")
cmd = "git clone {}.git".format(repo)


print(str(cmd))
return_value = subprocess.call(cmd, shell=True)
print("Return value:" + str(return_value))

Upvotes: 0

Yafaa
Yafaa

Reputation: 337

Just found this library gitpython

from git import Repo

Try

Repo.clone_from(url,repo)

OR

git.Git(PATH).clone(URL)

Upvotes: 2

Related Questions