Universal to Codeberg Migration Tool
A TypeScript tool to migrate all your GitHub or GitLab repositories to Codeberg with a single command.
- 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)
- 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
-
Clone this repository:
git clone <repository-url>
cd github-to-codeberg-migrator
-
Install dependencies:
-
Create a .env file in the root directory:
cp .env.local .env # Copy the example file
-
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)
-
Clone this repository:
git clone <repository-url>
cd github-to-codeberg-migrator
-
Install dependencies:
-
Create a .env file in the root directory:
cp .env.local .env # Copy the example file
-
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)
GitHub Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
- Click "Generate new token"
- 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)
- Generate the token and copy it
GitLab Personal Access Token
- Go to GitLab Settings > Access Tokens
- Click "New personal access token"
- Select the following scopes:
- read_api (to read projects)
- read_repository (to clone repositories)
- write_repository (to push to repositories)
- Generate the token and copy it
Codeberg Personal Access Token
- Go to Codeberg Settings > Applications > Personal Access Tokens
- Click "Generate New Token"
- Select the following scopes:
- repo (for private repositories) or public_repo (for public repositories only)
- Generate the token and copy it
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
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
Build and run the compiled version
bun run build
bun run start
| 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) |
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
⚠️ 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.
- 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
- Fork the repository
- Create a feature branch (git checkout -b feature/amazing-feature)
- Make your changes
- Commit your changes (git commit -m 'Add some amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.