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.

  • How to make a copy of GitHub repository at each commit using GitPython package in Python
  • Installing dependent Github-based packages with pip
  • can git send-email send diff patch of html format?
  • How is it possible to use raw_input() in a Python Git hook?
  • Jenkins build failed with Revision error
  • How to write a git hook to restrict writing to branch?
  • Using un-managed file in Jenkins build step
  • Replicating "git checkout <commit> with PyGit2
  • 5 Solutions collect form web for “Python way to clone a git repository”

    There is http://gitorious.org/git-python/ . 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
    git.Git().clone("git://gitorious.org/git-python/mainline.git")
    

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

    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)
    

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

    Github’s libgit2 binding, pygit2 provides a one-liner cloning a remote directory:

    clone_repository(url, path, 
        bare=False, repository=None, remote=None, checkout_branch=None, callbacks=None)
    

    With Dulwich tip you should be able to do:

    from dulwich.repo import Repo
    Repo("/path/to/source").clone("/path/to/target")
    

    This is still very basic – it copies across the objects and the refs, but it doesn’t yet create the contents of the working tree if you create a non-bare repository.

    My solution is very simple and straight forward. It doesn’t even need the manual entry of paraphrase/password.

    Here is my complete code:

    import os
    import sys
    
    path        =   "/path/to/store/your/cloned/project" 
    clone       =   "git clone gitolite@10.10.10.55:/your/project/name.git" 
    
    os.system("sshpass -p your_password ssh user_name@your_localhost")
    os.chdir(path) # Specifying the path where the cloned project has to be copied
    os.system(clone) # Cloning
    
    print "\n CLONED SUCCESSFULLY.! \n"
    
    Git Baby is a git and github fan, let's start git clone.