DEV Community

Cover image for How do I back up all my Github repositories?
Ismaël Maurice
Ismaël Maurice

Posted on

How do I back up all my Github repositories?


The goal of this article is to explain how to back up all your Github repositories with a utility script.

I wrote this script in order to be able to:

  • the personal user repositories private and public,
  • the user organization repositories,
  • the ancestor repositories,
  • the fork repositories.

When the script is run for the first time, it will retrieve all the repositories if the repositories have been previously retrieved it will do an update.

The repository name with space will be replace in clone folder by -. Example the repository name like repo 1 will be clone with name repo-1.


Before getting started, you'll need to install Python and Git on your machine:

Python >=3.9


After installation, you can clone the utility script at the following address: Github Clone Repo


Token creation

Go to your Github account to generate a token with read-only authorization as below:

Image description

Image description

If you want to update fork repositories, you need to give workflow authorization to allow repositories to be updated. Activate the option as shown below:

Image description

Initializing environment variables

In the clone utility project repository folder, create the file .env with the following contents:

# Clone repo host
# Domain protocol type http or https
PROTOCOL = https
# Access Token To Domain
TOKEN = your_generate_token_here
# Storage Folder => Folder where the repositories will be save => example /home/toto or C:\users\toto for windows
FOLDER = folder_path_here
Enter fullscreen mode Exit fullscreen mode

You must enter specific values as shown in the example below:

Image description

During execution, destination folders will be created if they do not exist.


  1. Run the following command in the project folder (must be run once):

        python -m venv env


        python3 -m venv env

    or for ubuntu

        virtualenv venv

    If you encounter an error, please check the following link:

  2. Run the following command to activate the environment:Lancez la commande suivante pour activer l'environnement:

    source env/bin/activate

    or on windows

  3. Install the modules from the command:

        pip install -r requirements.txt
  4. Run the backup script with the command: python or python3

At the end you'll have all the repositories in the destination folder.

Image description

Note that for each execution you have the log generated inside utility script folder inside subfolder logs.

For Gitlab version you can visit Gitlab Backup.

Top comments (0)