This tool is a Python script designed to automate the migration of Git repositories from a GitLab instance to a GitHub organization. It handles the creation of the repository on GitHub, mirrors the entire Git history, and assigns the new repository to a specified team within your GitHub organization.
The migration process is managed through a simple CSV file, allowing for easy batch processing of multiple repositories.
- Batch Migration: Migrates multiple repositories defined in a
repo_url.csv
file. - Organization & Team Support: Automatically creates repositories within a specified GitHub organization.
- Team Assignment: Adds the newly migrated repository to a designated team with
push
permissions. - Full History Mirror: Uses
git clone --bare
andgit push --mirror
to ensure all branches and tags are migrated perfectly. - Idempotent Creation: Safely skips repository creation on GitHub if the repository already exists, preventing errors on re-runs.
- Secure: Uses environment variables to handle sensitive access tokens securely.
Before you begin, ensure you have the following:
- Python 3: The script is written in Python 3.
- Git: The Git command-line tool must be installed and accessible in your system's PATH.
- Python Dependencies: The
requests
library is required. Install it via pip:pip install requests
- GitLab Personal Access Token:
- Create a token in your GitLab account with
read_api
andread_repository
scopes. - Go to User Settings > Access Tokens.
- Create a token in your GitLab account with
- GitHub Personal Access Token (Classic):
- Create a token in your GitHub account. For organization migrations, it's recommended to use a token from an organization owner.
- Required scopes:
repo
: For creating and writing to repositories.admin:org
: For adding repositories to teams.
- Go to Developer settings > Personal access tokens > Tokens (classic).
This script relies on environment variables for configuration and credentials. Create a .env
file in the project root or export them in your shell session.
# GitLab Configuration
GITLAB_URL="[https://gitlab.com](https://gitlab.com)" # Optional: Defaults to gitlab.com if not set
GITLAB_TOKEN="your_gitlab_personal_access_token"
# GitHub Configuration
GITHUB_TOKEN="your_github_personal_access_token"
GITHUB_USER_NAME="your_github_username" # The username associated with the GITHUB_TOKEN
GITHUB_REPO_PRIVATE="True" # Set to "True" for private repos, "False" for public