The original gitlab-mirror-maker repo has been archived by its owner, but I like the project and have some ideas for features that would make it even better. So I'll implement those here instead.
Changes so far:
- Swapped out API access via raw requests for API wrapper libraries
(python-gitlab and
PyGithub) instead
- This immediately fixes an issue the original gitlab-mirror-maker has with pagination.
- Added
REPO
argument to CLI to allow mirroring only a single repository instead of all of them - Added
--target-forks
CLI option to allow setting up mirrors that push towards repositories which are themselves forks- Useful if you want to make clear that a repo is a fork on both GitLab and GitHub
- You have to fork manually on both ends, but the mirror will be set up automatically by gitlab-mirror-maker
- Switched from
click
totyper
andtqdm
for CLI and progress bar, respectively (no immediate user improvement, just more modern) - Added more extensive information on mirror status (e.g. if it appears to be working, is up-to-date, has the desired description format etc.) which will be summarized in the table
- Split up into several CLI commands:
list
,show
andmirror
README of original gitlab-mirror-maker (with changes only to the help text) below, most of which of course doesn't apply to this fork. Bear with me while I set things up here.
GitLab Mirror Maker is a small tool written in Python that automatically mirrors your public repositories from GitLab to GitHub.
- Maybe you like GitLab better but the current market favors developers with a strong GitHub presence?
- Maybe as a form of backup?
- Or maybe you have other reasons... 😉
Install with pip or pipx:
pip install gitlab-mirror-maker
There's also a Docker image available:
docker run registry.gitlab.com/grdl/gitlab-mirror-maker
Run: gitlab-mirror-maker --github-token xxx --gitlab-token xxx
See Authentication below on how to get the authentication tokens.
Instead of using cli flags you can provide configuration via environment variables with the MIRRORMAKER_
prefix:
export MIRRORMAKER_GITHUB_TOKEN xxx
export MIRRORMAKER_GITLAB_TOKEN xxx
gitlab-mirror-maker
Run with --dry-run
flag to only print the summary and don't make any changes.
Usage: gitlab-mirror-maker [OPTIONS] [REPO]
Set up mirroring of repositories from GitLab to GitHub.
By default, mirrors for all repositories owned by the user will be set up.
If the REPO argument is given, a mirror will be set up for that repository
only. REPO can be either a simple project name ("myproject"), in which
case its namespace is assumed to be the current user, or the path of a
project under a specific namespace ("mynamespace/myproject").
Options:
--version Show the version and exit.
--github-token TEXT GitHub authentication token [required]
--gitlab-token TEXT GitLab authentication token [required]
--github-user TEXT GitHub username. If not provided, your
GitLab username will be used by default.
--target-forks / --no-target-forks
Allow forks as target repos for pushing.
--dry-run / --no-dry-run If enabled, a summary will be printed and no
mirrors will be created.
--help Show this message and exit.
GitLab Mirror Maker uses the remote mirrors API to create push mirrors of your GitLab repositories.
For each public repository in your GitLab account a new GitHub repository is created using the same name and description. It also adds a [mirror]
suffix at the end of the description and sets the website URL the original GitLab repo. See the mirror of this repo as an example.
Once the mirror is created it automatically updates the target GitHub repository every time changes are pushed to the original GitLab repo.
Only public repositories are mirrored to avoid publishing something private.
Only the commits, branches and tags are mirrored. No other repository data such as issues, pull requests, comments, wikis etc. are mirrored.
GitLab Mirror Maker needs authentication tokens for both GitLab and GitHub to be able to create mirrors.
- Click on your GitLab user -> Settings -> Access Tokens
- Pick a name for your token and choose the
api
scope - Click
Create personal access token
and save it somewhere secure - Do not share it! It grants full access to your account!
Here's more information about GitLab personal tokens.
- Click on your GitHub user -> Settings -> Developer settings -> Personal access tokens -> Generate new token
- Pick a name for your token and choose the
public_repo
scope - Click
Generate token
and save it somewhere secure
Here's more information about GitHub personal tokens.
Instead of running the tool manually you may want to schedule it to run periodically with GitLab CI to make sure that any new repositories are automatically mirrored.
Here's a .gitlab-ci.yml
snippet you can use:
job:
image: python:3.8-alpine
script:
- pip install gitlab-mirror-maker
- gitlab-mirror-maker
only:
- schedules
Here's more info about creating scheduled pipelines with GitLab CI.