Clone or pull all your github repos (possible as basis for a backup)

07 Nov 2019 - tsp
Last update 08 Nov 2019
Reading time 1 min

What’s this all about

Basically it’s just a short summary on how to automate fetching a list of all your repositories on GitHub (private and public) and keep your local copies in sync. This could be used on a backup machine or as the basis of a backup to never forget cloning a repository or pulling content. It’s just a short script to automate - to reduce error probability.

GitHub offers an extensive API where one can use functions either after OAuth authentication (good idea for interactive web applications), access tokens (a good idea for long running services, desktop applications, etc.) or currently user and password via HTTP basic authentication which will be disabled soon - and is a bad idea in case of enabled 2FA too.

How does it work?

First the script requires an access token with permission to access private repositories. This can be created in the account settings under the developer tab.

This token is used to fetch a list of all repositories owned by the specified user. This list is basically a JSON array containing much additional metainformation. The script used in this blog post is not doing proper JSON parsing but instead is separating everything via regular expressions. So each repository clone URI is extracted - and then the repository names are extracted from that cloen URI.

After that the script iterates over all repositories, checks if they are present and if not performs the clone. If they are present a pull operation is executed for every repository.

The Code

The code is available as a GitHub Gist.

This article is tagged:


Data protection policy

Dipl.-Ing. Thomas Spielauer, Wien (webcomplains389t48957@tspi.at)

This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/

Valid HTML 4.01 Strict Powered by FreeBSD IPv6 support