The purpose of this program is to make backing up all of a user's github repos an automated process instead of cloning each repo one by one. This program is not automatic in the sense of cloning repos on its own on a schedule. It is automatic in the sense that it queries github's API for a list of a user's repos and then iterates over that list, cloning each repo in turn.
This automation allows a user to avoid keeping track of all of his/her repos and cloning them individually.
I am hoping to create an executable to store on a thumbdrive and allow the user to run the executable from the command line and clone the repos to the thumb drive.
This code requires the user to have already authenticated his/her machine with Github. In my experience, when the user tries to push to a repo they must authenticate. Git stores the credentials for Github in Windows Credential Manager.
** Since we are only cloning public repos, we should not have to authenticate. If we are cloning private repos, then the machine should be authenticated and credentials stored **
- Query Github API for json of all of a user's repos
- For each repo in json
- extract url
- git clone --mirror url
- Clone This Repo
- cd github-backup
- python -m pip install -r requirements.txt
- . .venv/scripts/activate
- pyinstaller -F backup.py
- Copy .exe from dist folder
- Paste .exe in your backup drive (usb, external, etc)
- cd to the DRIVE and DIRECTORY with backup.exe
PS C:\Users\user> cd D:\- ./backup <gh_username> <repo_limit>
PS D:\> ./backup <username> <limit>- <gh_username> is your github username
- <repo_limit> a number above the amount of repos in your account for github's API
- cd to directory where you want to clone repos
- git clone path/to/source/folder
- https://gist.github.com/plembo/a786ce2851cec61ac3a051fcaf3ccdab how to use git package to clone repo from within python
- https://stackoverflow.com/questions/11113896/use-git-commands-within-python-code suggest python subprocess module
- https://graphite.dev/guides/git-clone-bare-mirror what is mirror?
- https://stackoverflow.com/questions/15275338/when-doing-a-git-clone-mirror-where-are-the-actual-files how to clone from mirror
- https://stackoverflow.com/questions/21045061/git-clone-from-another-directory how to clone from mirror locally
Copyright 2025 Theodore Podewil
GPL-3.0-or-later
/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. */