Tool to backup your GitHub and GitLab repositories
Switch branches/tags
Clone or download
Latest commit 1de5c46 Jun 15, 2018
Failed to load latest commit information.
appveyor.yml Update appveyor Mar 19, 2017
backup.go Test fixes + minor changes for GitLab API v4 Jun 13, 2018
client.go Test fixes + minor changes for GitLab API v4 Jun 13, 2018

gitbackup - Backup your GitHub and GitLab repositories

Linux/Mac OS X Build Status Windows Build status

gitbackup is a tool to backup your git repositories from GitHub (including GitHub enterprise) or GitLab (including custom GitLab installations).

gitbackup only creates a backup of the repository and does not currently support issues, pull requests or other data associated with a git repository. This may or may not be in the future scope of this tool.

If you are following along my Linux Journal article, please obtain the version of the source tagged with lj-0.1.

Using gitbackup

Binary releases are available from the Releases page. Please download the ZIP corresponding to your OS and architecture and unzip the binary somewhere in your $PATH.

gitbackup requires a GitHub API access token for backing up GitHub repositories and GitLab personal access token for GitLab. You can supply the token to gitbackup using GITHUB_TOKEN and GITLAB_TOKEN environment variables respectively.

Typing -help will display the command line options that gitbackup recognizes:

$ gitbackup -help
Usage of ./bin/gitbackup:
  -backupdir string
    	Backup directory
  -githost.url string
    	DNS of the custom Git host
  -github.repoType string
    	Repo types to backup (all, owner, member) (default "all")
  -gitlab.projectVisibility string
    	Visibility level of Projects to clone (default "internal")
  -service string
    	Git Hosted Service Name (github/gitlab)

Backing up your GitHub repositories

To backup all your GitHub repositories to the default backup directory ($HOME/.gitbackup/):

$ GITHUB_TOKEN=secret$token gitbackup -service github

To backup only the GitHub repositories which you are the "owner" of:

$ GITHUB_TOKEN=secret$token gitbackup -service github -github.repoType owner

To backup only the GitHub repositories which you are the "member" of:

$ GITHUB_TOKEN=secret$token gitbackup -service github -github.repoType member

Backing up your GitLab repositories

To backup all projects which have their visibility set to "internal" on to the default backup directory ($HOME/.gitbackup/):

$ GITLAB_TOKEN=secret$token gitbackup -service gitlab

To backup only the GitLab projects which are "public"

$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -gitlab.projectVisibility public

To backup only the private repositories:

$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -gitlab.projectVisibility private

GitHub Enterprise or custom GitLab installation

To specify a custom GitHub enterprise or GitLab location, specify the service as well as the the githost.url flag, like so

$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -githost.url

Specifying a backup location

To specify a custom backup directory, we can use the backupdir flag:

$ GITHUB_TOKEN=secret$token gitbackup -service github -backupdir /data/

This will create a directory in /data and backup all your repositories there instead. Similarly, it will create a directory, if you are backing up repositories from gitlab. If you have specified a Git Host URL, it will create a directory structure data/host-url/.


If you have Golang 1.7 or 1.8 installed, you can clone the repository and:

$ go build 

The built binary will be gitbackup.