DEV Community

Cover image for Python script for cloning repositories
Nicolas Sebastian Vidal
Nicolas Sebastian Vidal

Posted on

Python script for cloning repositories

A couple times it happened to me this year that I had to pull again the repositories from a given organization.

Mostly it happened to me because my computer broke, so a friend of mine lend me his computer so I could work. After mine was fixed I had to pull everything again.

So for not having to clone the repositories manually I wrote a Python 3 script for doing it for me:

The name of the organization is the GitHub username. So for example Facebook GitHub URL is https://github.com/facebook, if you would like to clone all their repositories you will have to replace organization-name-goes-here with facebook.

If you don't know how to create a personal access token, click the link for going to the GitHub documentation. It is well explained with screenshots of where to go and everything. Once you get it, you will have to place it where it says token-goes-here.

If you don't know how to install different versions of python on your machine, you could take a look to:

You will need to install PyGithub the library that I'm importing in the script:

pip install PyGithub
Enter fullscreen mode Exit fullscreen mode

If you don't have pip installed, take a look here for setting it up properly.

Finally for running the script you just need to write in the terminal of your choice:

python cloner.py
Enter fullscreen mode Exit fullscreen mode

Where cloner.py is the name of the file where we wrote our script. Be aware that all repositories will be cloned in the path where you are executing the script.

Have a great week everyone!!

Top comments (0)