This Python script allows you to backup all your GitHub repositories (both public and private) by cloning them to your local machine.
- Clones repositories: Clones all repositories from your GitHub account (public, private, or both).
- Fork management: Optionally include forked repositories.
- Customization: Allows you to select whether to clone public, private, or both types of repositories.
-
Clone the repository:
git clone https://github.com/psparwez/github-backup-script.git cd github-backup-script -
Create a virtual environment:
- For Windows:
python -m venv .venv .\.venv\Scripts\activate
- For macOS/Linux:
python3 -m venv .venv source .venv/bin/activate - For Windows:
-
Install the dependencies:
pip install -r requirements.txt
You need to generate a GitHub Personal Access Token (PAT) with the repo scope to access private repositories.
- Go to GitHub Tokens Settings and create a token with
repopermissions. - Copy your token.
In the main.py script, replace the GITHUB_TOKEN variable with your actual GitHub token:
GITHUB_TOKEN = 'your_github_token' # Replace with your GitHub tokenExecute the script by running the following command:
python main.py? Do you want to clone forked repositories as well? No
? Which type of repositories do you want to clone? public
Fetching your repositories...
Found repo: demo (Public)
Found repo: test (Public)
Do you want to proceed with cloning these repositories? Yes
Cloning repository: demo...
Cloning repository: test...
Successfully cloned: demo
Successfully cloned: test