07 Nov 2019 - tsp
Last update 08 Nov 2019
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.
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 is available as a GitHub Gist.
This article is tagged:
Dipl.-Ing. Thomas Spielauer, Wien (firstname.lastname@example.org)
This webpage is also available via TOR at http://coihcmhmb6cg6bvtelykwlte45yqhxkl6ffdoco5kc3a4qn3uno53oqd.onion/