How to Clone Repository using GitPython

2.3k views Asked by At

I am new to Python and Git. Found GitPython library to run Git commands using Python. I am trying to clone an already created private repository on Google Cloud to my local directory on Mac. My code is as follow:

repo = Repo.clone_from('https://source.developers.google.com/p/my-project/r/my-project--data', 'my-local-dir', no_checkout=True)

And I am getting following error:

git.exc.GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git clone --no-checkout -v https://source.developers.google.com/p/my-project/r/my-project-data /my-local-dir stderr: 'Cloning into '/my-local-dir'... fatal: could not read Username for 'https://source.developers.google.com': Device not configured

Please help. Thanks in advance.

1

There are 1 answers

0
Flaviano Flauber On

I was trying to the same thing, then I discoverd pygit2, and with it I was able to clone a repository using two lines.

How? First make sure you have installed pygit2 in your python environment. I did that using the following command line:

pip install pygit2

Here the two lines I mentioned above:

import pygit2
pygit2.clone_repository("https://github.com/libgit2/pygit2", "pygit2")