Python way to clone a git repository

Mike picture Mike · Mar 18, 2010 · Viewed 163.1k times · Source

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.

Answer

Amir Ali Akbari picture Amir Ali Akbari · Mar 13, 2013

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.