2
1
Fork
You've already forked github_to_codeberg
0
GitHub to Codeberg Organization Migration Tool
  • Go 100%
2025年09月04日 18:58:26 +02:00
api first commit 2025年09月04日 18:48:21 +02:00
console first commit 2025年09月04日 18:48:21 +02:00
go.mod first commit 2025年09月04日 18:48:21 +02:00
go.sum first commit 2025年09月04日 18:48:21 +02:00
LICENSE.md first commit 2025年09月04日 18:48:21 +02:00
main.go first commit 2025年09月04日 18:48:21 +02:00
README.md Change minimum Go version required 2025年09月04日 18:58:26 +02:00

GitHub to Codeberg Migration Tool

This interactive command-line program facilitates the migration of Git repositories from a GitHub organization to a Codeberg organization. It guides the user through the process of connecting to both APIs, selecting repositories, and performing the necessary Git operations.

Features

  • Interactive Prompts: Guides the user through each step with clear, interactive command-line prompts.
  • API Connection Validation: Verifies GitHub and Codeberg API tokens and organization existence.
  • Flexible Repository Selection: Allows selection of specific repositories from GitHub using individual numbers (e.g., 1,3,5), ranges (e.g., 2-8), or migrating all of them. Automatically handles duplicate selections.
  • Flexible Git Configuration: Supports both SSH and HTTPS authentication for Git operations, with credential prompts for HTTPS.
  • Existing Repository Handling: Detects if a repository already exists on Codeberg and offers to force-migrate (delete and recreate) or skip.
  • Comprehensive Migration: Migrates main repository content (branches, tags) and optionally wikis.
  • Migration Summary: Provides a detailed summary of all migration operations performed at the end.
  • Colored Output: Uses ANSI escape codes to provide a more readable and user-friendly console output with colored messages for status, prompts, success, and errors.

Table of Contents

Prerequisites

Before running this program, ensure you have the following:

  • Go (Golang): Version 1.25 or higher.
  • Git: Installed and configured on your system.
  • GitHub Personal Access Token (PAT):
    • With repo scope (for full control over private repositories) or public_repo (for public repositories only).
    • Generated from GitHub Developer Settings.
  • Codeberg Personal Access Token (PAT):
    • With write:repository and delete:repository scopes (for creating, deleting, and pushing to repositories) plus read:org (for reading organization state).
    • Generated from Codeberg User Settings.
  • SSH Keys (Optional, for SSH Git operations): If you choose to use SSH for Git operations, ensure your SSH keys are set up and added to both your GitHub and Codeberg accounts.

Getting Started

Follow these steps to get the project up and running on your local machine.

1. Clone the repository

git clone https://codeberg.org/bvaudour/github_to_codeberg.git
cd github_to_codeberg

2. Build the application

go build -o github-to-codeberg-migrator main.go

3. Run the application

./github-to-codeberg-migrator

Usage Guide

Once you run the application, it will guide you through the migration process with a series of interactive prompts.

GitHub Connection Parameters

The program will first ask for your GitHub organization name and a Personal Access Token (PAT).

--- GitHub Connection Parameters ---
GitHub Organization Name: your-github-org
GitHub Personal Access Token (PAT): ****************************************
GitHub connection successful.

The program will validate these credentials. If they are incorrect, it will inform you of the issue (invalid token or organization not found) and give you the option to retry or exit.

Codeberg Connection Parameters

Next, it will prompt for your Codeberg organization name and PAT.

--- Codeberg Connection Parameters ---
Codeberg Organization Name: your-codeberg-org
Codeberg Personal Access Token (PAT): ****************************************
Codeberg connection successful.

Similar to GitHub, these credentials will be validated.

Repository Selection

After successfully connecting to GitHub, the program will fetch and display a list of all repositories in your GitHub organization.

--- Available GitHub Repositories ---
1. my-public-repo (Private: false)
2. my-private-app (Private: true)
3. another-repo (Private: false)
Select repositories to migrate (e.g., 1,3,5 or 2-8), 'a' to select all, or 'q' to quit: 1,3,2-3
You have selected 3 repositories for migration.

You can:

  • Enter comma-separated numbers (e.g., 1,3) to select specific repositories.
  • Specify ranges (e.g., 2-8) to select all repositories within that range.
  • Combine individual numbers and ranges (e.g., 1,3,5-7). Duplicate entries will be automatically ignored.
  • Type a to select all available repositories.
  • Type q to quit the program.

Git Configuration (GitHub)

The program will then ask your preference for Git operations (cloning) from GitHub.

--- Git Configuration for GitHub ---
Do you want to use SSH for Git operations for GitHub? (y/n): y
  • If you select y (yes), it will use the SSH clone URL. Ensure your SSH keys are set up.
  • If you select n (no), it will use the HTTPS clone URL and prompt for your GitHub username and password/PAT for authentication.

Git Configuration (Codeberg)

You will then provide similar Git configuration for pushing to Codeberg.

--- Git Configuration for Codeberg ---
Do you want to use SSH for Git operations for Codeberg? (y/n): n
Please provide credentials for HTTPS authentication for Codeberg.
Git username for Codeberg: your-codeberg-username
Password/Access Token for Codeberg: ****************************************
  • If y (yes), it will use the SSH URL for pushing.
  • If n (no), it will use the HTTPS URL and prompt for your Codeberg username and password/PAT.

Migration Process

The program will then iterate through your selected GitHub repositories and perform the migration:

  1. Check Existence on Codeberg: It first checks if a repository with the same name already exists on Codeberg.
  2. Handle Existing Repositories:
    • If it exists, you'll be asked if you want to force migration (delete the existing one and recreate it).
    • If you choose y, it will attempt to delete the Codeberg repository, then recreate it.
    • If you choose n, the migration for that specific repository will be skipped.
  3. Create Repository on Codeberg: If the repository doesn't exist (or was just deleted), it will be created on Codeberg with the same name, description, privacy setting, and wiki status as the GitHub source.
  4. Git Data Migration: The program will clone the GitHub repository locally, add the Codeberg repository as a remote, and then push all branches and tags to Codeberg. This includes wiki migration if wikis are enabled on both platforms.
--- Starting Repository Migration ---
Processing GitHub repository 'my-public-repo'...
Creating repository 'my-public-repo' on Codeberg'...
Codeberg repository created successfully.
Migrating Git data for 'my-public-repo'...
Migration of 'my-public-repo' completed successfully.
Processing GitHub repository 'my-private-app'...
Repository 'my-private-app' already exists on Codeberg.
Do you want to force migration (delete existing and recreate)? (y/n): y
Deleting repository 'my-private-app' on Codeberg'...
Codeberg repository deleted successfully. Recreating...
Creating repository 'my-private-app' on Codeberg'...
Codeberg repository created successfully.
Migrating Git data for 'my-private-app'...
Migration of 'my-private-app' completed successfully.

Migration Summary

Finally, after all selected repositories have been processed, the program will display a summary of each migration's outcome.

=== Migration Summary ===
Repository: my-public-repo
 Status: Success
 Codeberg URL: https://codeberg.org/your-codeberg-org/my-public-repo
---
Repository: my-private-app
 Status: Deleted and Recreated
 Codeberg URL: https://codeberg.org/your-codeberg-org/my-private-app
---
Repository: another-repo
 Status: Ignored (already exists)
 Error: migration ignored because repository already exists and forced deletion was not chosen
---
Migration program finished.

Development

This project is written in Go and structured into main.go and two modules: api and prompt.

  • api/: Contains the core logic for interacting with GitHub and Codeberg APIs (github.go, codeberg.go), repository definitions (repo.go), Git operations (migrate.go), and HTTP request handling (request.go).
  • prompt/: Provides utility functions for interactive command-line prompts (prompt.go).
  • main.go: Orchestrates the entire migration flow, using functions from api and prompt.

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

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