Lei Mao bio photo

Lei Mao

Machine Learning, Artificial Intelligence. On the Move.

Twitter Facebook LinkedIn GitHub   G. Scholar E-Mail RSS

Introduction

GitHub is a web-based hosting service for version control using Git. People actually stored a lot of public and private code on GitHub, because it is popular and usually reliable. However, there is still some probability in theory that GitHub server will go down and lose your precious code, or your account will be stolen and your repositories will be deleted maliciously. So you do want to have your code backed up on your local computer in case those unfortunate things happen.


Then how are you going to do that if you have hundreds of repository on your GitHub. I believe you could not do this easily using Git, GitHub Desktop, or GitKraken. Fortunately, Jose Diaz-Gonzalez from GitHub open source community has developed a tool which allows us to backup different kind of repositories easily. The tool is very powerful, but I will just give a simple tutorial on how to backup your public and private repositories to your local computer. For more advanced backup requirements, please visit the repository on GitHub for details.

Tutorial

Requirements

  • Git 1.9+

Software Installation

Use Pip to install the software.

$ pip install github-backup

Generate GitHub Token

Go to https://github.com/settings/tokens and generate a personal access token.

Start to Backup

To backup all of your repositories, including private repositories, please run the following command in the terminal.

$ github-backup leimao --token <personal-access-token> --private --repositories --output-directory ~/Backup/leimao

Here leimao is my GitHub account, <personal-access-token> is the personal access token you just generated. ~/Backup/leimao is the target directory where I want to save my repositories.

Security Concerns

Some people were worried about leaking access of GitHub to third parties. I think one may delete the token after the entire GitHub was backed up.

References