Skip to content

Move your all repositories from GitHub to Codeberg.com

Notifications You must be signed in to change notification settings

an1ndra/github-to-codeberg

Repository files navigation

Universal to Codeberg Migration Tool

A TypeScript tool to migrate all your GitHub or GitLab repositories to Codeberg with a single command.

Features

  • Fetch all your GitHub or GitLab repositories (public, private, and forks)
  • Create corresponding repositories on Codeberg
  • Clone and push all branches and tags from source to Codeberg
  • Preserve commit history and repository metadata
  • Handle both public and private repositories
  • Support for both GitHub and GitLab sources
  • Check for existing repositories on Codeberg to avoid duplicates
  • Option to delete source repositories after successful migration (DANGEROUS)

Prerequisites

  • Node.js (v16 or later) OR Bun
  • Git
  • GitHub Personal Access Token with appropriate scopes (if migrating from GitHub)
  • GitLab Personal Access Token with appropriate scopes (if migrating from GitLab)
  • Codeberg Personal Access Token with appropriate scopes

Setup

Using npm:

  1. Clone this repository:

    git clone <repository-url>
    cd github-to-codeberg-migrator
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory:

    cp .env.local .env  # Copy the example file
  4. Configure your environment variables in the .env file:

    • GITHUB_TOKEN: Your GitHub Personal Access Token (required if migrating from GitHub)
    • GITLAB_TOKEN: Your GitLab Personal Access Token (required if migrating from GitLab)
    • CODEBERG_TOKEN: Your Codeberg Personal Access Token (required)
    • GITHUB_USERNAME: Your GitHub username (required if migrating from GitHub)
    • GITLAB_USERNAME: Your GitLab username (required if migrating from GitLab)
    • CODEBERG_USERNAME: Your Codeberg username (required)
    • CODEBERG_BASE_URL: Your Codeberg instance URL (optional, defaults to https://codeberg.org)

Using Bun:

  1. Clone this repository:

    git clone <repository-url>
    cd github-to-codeberg-migrator
  2. Install dependencies:

    bun install
  3. Create a .env file in the root directory:

    cp .env.local .env  # Copy the example file
  4. Configure your environment variables in the .env file:

    • GITHUB_TOKEN: Your GitHub Personal Access Token (required if migrating from GitHub)
    • GITLAB_TOKEN: Your GitLab Personal Access Token (required if migrating from GitLab)
    • CODEBERG_TOKEN: Your Codeberg Personal Access Token (required)
    • GITHUB_USERNAME: Your GitHub username (required if migrating from GitHub)
    • GITLAB_USERNAME: Your GitLab username (required if migrating from GitLab)
    • CODEBERG_USERNAME: Your Codeberg username (required)
    • CODEBERG_BASE_URL: Your Codeberg instance URL (optional, defaults to https://codeberg.org)

Getting Access Tokens

GitHub Personal Access Token

  1. Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
  2. Click "Generate new token"
  3. Select the following scopes:
    • repo (for private repositories) or public_repo (for public repositories only)
    • read:org (if you have organization repositories)
    • read:user (to read user profile)
    • user:email (to read email addresses)
  4. Generate the token and copy it

GitLab Personal Access Token

  1. Go to GitLab Settings > Access Tokens
  2. Click "New personal access token"
  3. Select the following scopes:
    • read_api (to read projects)
    • read_repository (to clone repositories)
    • write_repository (to push to repositories)
  4. Generate the token and copy it

Codeberg Personal Access Token

  1. Go to Codeberg Settings > Applications > Personal Access Tokens
  2. Click "Generate New Token"
  3. Select the following scopes:
    • repo (for private repositories) or public_repo (for public repositories only)
  4. Generate the token and copy it

Usage

Using npm:

Run the migration from GitHub

npm run migrate:github
# or
npx ts-node migrate-universal-to-codeberg.ts --source github

Run the migration from GitLab

npm run migrate:gitlab
# or
npx ts-node migrate-universal-to-codeberg.ts --source gitlab

Include forks in migration (optional)

npx ts-node migrate-universal-to-codeberg.ts --source github --include-forks
# or
npx ts-node migrate-universal-to-codeberg.ts --source gitlab --include-forks

Migrate and delete forks after successful migration (DANGEROUS)

npx ts-node migrate-universal-to-codeberg.ts --source github --include-forks --delete-source
# or
npx ts-node migrate-universal-to-codeberg.ts --source gitlab --include-forks --delete-source

Delete source repositories after successful migration (DANGEROUS)

npm run migrate:github:delete
# or
npm run migrate:gitlab:delete

IMPORTANT: This option will delete repositories from the source platform (GitHub/GitLab) after they have been successfully migrated to Codeberg. This action is irreversible. The script will give you 10 seconds to cancel by pressing Ctrl+C before proceeding.

Build and run the compiled version

npm run build
npm run start

Using Bun:

Run the migration from GitHub directly (no compilation needed)

bun run migrate-universal-to-codeberg.ts --source github
# or
bun run migrate:bun:github

Run the migration from GitLab directly (no compilation needed)

bun run migrate-universal-to-codeberg.ts --source gitlab
# or
bun run migrate:bun:gitlab

Include forks in migration (optional)

bun run migrate-universal-to-codeberg.ts --source github --include-forks
# or
bun run migrate-universal-to-codeberg.ts --source gitlab --include-forks

Migrate and delete forks after successful migration (DANGEROUS)

bun run migrate-universal-to-codeberg.ts --source github --include-forks --delete-source
# or
bun run migrate-universal-to-codeberg.ts --source gitlab --include-forks --delete-source

Delete source repositories after successful migration (DANGEROUS)

bun run migrate-universal-to-codeberg.ts --source github --delete-source
# or
bun run migrate-universal-to-codeberg.ts --source gitlab --delete-source

IMPORTANT: This option will delete repositories from the source platform (GitHub/GitLab) after they have been successfully migrated to Codeberg. This action is irreversible. The script will give you 10 seconds to cancel by pressing Ctrl+C before proceeding.

Hot reload development mode

bun run dev:bun

Build and run the compiled version

bun run build
bun run start

Environment Variables

Variable Description Required
GITHUB_TOKEN GitHub Personal Access Token Only if migrating from GitHub
GITLAB_TOKEN GitLab Personal Access Token Only if migrating from GitLab
CODEBERG_TOKEN Codeberg Personal Access Token Yes
GITHUB_USERNAME Your GitHub username Only if migrating from GitHub
GITLAB_USERNAME Your GitLab username Only if migrating from GitLab
CODEBERG_USERNAME Your Codeberg username Yes
CODEBERG_BASE_URL Your Codeberg instance URL No (defaults to https://codeberg.org)

Configuration

The migration script will:

  • Fetch all your GitHub or GitLab repositories (excluding forks by default)
  • Check if repositories already exist on Codeberg to avoid duplicates
  • Create new repositories with the same name on Codeberg (if they don't exist)
  • Clone each repository from the source (GitHub or GitLab)
  • Push all branches and tags to Codeberg
  • Preserve commit history and repository settings
  • Optionally delete source repositories after successful migration

Warning

⚠️ Important: This tool will create repositories on Codeberg and push your code. Make sure your access tokens have the correct permissions before running the migration.

⚠️ Dangerous Option: The --delete-source flag will permanently delete repositories from GitHub/GitLab after successful migration. This action is irreversible. Only use this option when you're certain your data is safely migrated to Codeberg.

Troubleshooting

  • If you get authentication errors, verify that your tokens are correct and have the required scopes
  • For large repositories, the migration may take a while
  • If the migration fails for a specific repository, check the error output for details
  • Make sure you have enough storage space on Codeberg for all your repositories

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Move your all repositories from GitHub to Codeberg.com

Topics

Resources

Stars

Watchers

Forks