Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active September 19, 2024 02:17
Show Gist options
  • Save plembo/a786ce2851cec61ac3a051fcaf3ccdab to your computer and use it in GitHub Desktop.
Save plembo/a786ce2851cec61ac3a051fcaf3ccdab to your computer and use it in GitHub Desktop.
Clone git repo using GitPython

Git clone using GitPython

In general, I find GitPython's doc to be difficult to parse, mostly because the examples are written in the same kind of manpage notation that gave me a steep learning curve back when I was first learning Unix.

After searching for awhile, I found this page of the doc that tries to show how to clone a remote repo:

https://gitpython.readthedocs.io/en/stable/tutorial.html#examining-references

I didn't find it that obvious, and had to do some trial and error in the python shell before I got it right.

Here's an actual working example you can try:

import git

repo = git.Repo.clone_from('[email protected]:philnc/onemoretech.git',
                           '/tmp/onemoretech',
                           branch='master')

The repo will show up in your '/tmp' directory. To have it saved somewhere else, simply change the second path in the command above ('/tmp/onemoretech') to something else (for example, '/home/myuser/projects').

@ChoiceBANKsampleritgithub

nice

@balee323
Copy link

balee323 commented Apr 9, 2024

I very much agree with you on reading the GitPython documentation / API reference to be difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment