GitLab to GitHub Auto Update

GitLab to GitHub Auto Update is a Python tool that automates the import and mirroring of all your GitLab projects into GitHub. It handles bulk operations, auto-creates missing repos, and invokes GitHub’s Import API to keep both platforms in sync.

Features

Requirements

Installation

  1. Clone this repository:
    git clone https://gitlab.com/bocaletto-luca/gitlab-to-github-auto.git
  2. Enter the project directory:
    cd gitlab-to-github-auto
  3. (Optional) Create and activate a virtual environment:
    python3 -m venv venv
    source venv/bin/activate
  4. Install dependencies:
    pip install requests

Configuration

Open gitlab_to_github_auto_update.py and set your credentials:

# GitLab settings
GITLAB_URL      = "https://gitlab.com/api/v4"
GITLAB_TOKEN    = "your_gitlab_token_here"
GITLAB_USERNAME = "bocaletto-luca"

# GitHub settings
GITHUB_API_URL  = "https://api.github.com"
GITHUB_TOKEN    = "your_github_token_here"
GITHUB_USERNAME = "bocaletto-luca"

Note: Never commit your tokens in plaintext. Use environment variables or a .env file excluded from version control.

Usage

Run the script to start syncing:

chmod +x gitlab_to_github_auto_update.py
./gitlab_to_github_auto_update.py

Or simply:

python3 gitlab_to_github_auto_update.py

You will see console output showing which repos were created or already existed, and the status of each import trigger.

How It Works

  1. Fetch Projects: Calls GitLab’s /projects?membership=true endpoint, handling pagination.
  2. Check/Create on GitHub: Uses GET /repos/{user}/{repo} and POST /user/repos if missing.
  3. Trigger Import: Invokes PUT /repos/{user}/{repo}/import on GitHub, passing vcs_url and credentials for private repos.

Contributing

Contributions, bug reports and feature requests are welcome! Please:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a Merge Request on GitLab.

License

This project is released under the MIT License. See LICENSE for details.