Python way to clone a git repository


Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend.

3/18/2010 6:55:14 PM

Accepted Answer

There is GitPython. Haven’t heard of it before and internally, it relies on having the git executables somewhere; additionally, they might have plenty of bugs. But it could be worth a try.

How to clone:

import git

(It’s not nice and I don’t know if it is the supported way to do it, but it worked.)

12/4/2018 6:35:59 PM

Using GitPython will give you a good python interface to Git.

For example, after installing it (pip install gitpython), for cloning a new repository you can use clone_from function:

from git import Repo

Repo.clone_from(git_url, repo_dir)

See the GitPython Tutorial for examples on using the Repo object.

Note: GitPython requires git being installed on the system, and accessible via system's PATH.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow