Search code examples
pythongitpython

Cloning a private Github repo using a script


How to clone a private repository from Github using python?

I found some good information about git and python, but I started learning python few days back.


Solution

  • There is a library, libgit2, which enables git to be used as a shared library more helpful to your cause is the python binding's pygit.

    To answer your question using pygit to clone a repo:

    >>> from pygit2 import clone_repository
    >>> repo_url = 'git://github.com/libgit2/pygit2.git'
    >>> repo_path = '/path/to/create/repository'
    >>> repo = clone_repository(repo_url, repo_path) # Clones a non-bare repository
    >>> repo = clone_repository(repo_url, repo_path, bare=True) # Clones a bare repository
    

    You can view the repository based docs here