Github to Codeberg Bulk Migration Script

Cover Image for Github to Codeberg Bulk Migration Script
Rahul M. Juliato
Rahul M. Juliato
#codeberg#github# migration

Are you considering migrating your GitHub repositories to Codeberg but finding the process daunting? Look no further! In this blog post, we introduce a powerful solution: the "Github to Codeberg Bulk Migration Script." This script offers a nice way to transfer your projects from GitHub to Codeberg, leveraging automation to simplify the process.

In recent years, the landscape of code hosting platforms has expanded beyond the traditional giants. Codeberg, a community-driven and open-source alternative to GitHub, has gained traction among developers seeking a platform aligned with principles of privacy, transparency, and community governance. In this blog post, we'll explore how to migrate your repositories from GitHub to Codeberg using a simple and efficient migration script.

Why Codeberg?

Codeberg is indeed a noteworthy alternative to GitHub, particularly for those seeking an open-source and community-driven platform. Here's why Codeberg stands out:

Open Source Philosophy: Codeberg operates on an open-source philosophy, ensuring transparency and fostering a collaborative environment where developers can freely contribute to projects.

Privacy and Data Sovereignty: Codeberg prioritizes user privacy and data sovereignty, providing a platform where users have control over their data and can trust that it won't be exploited for commercial purposes.

Community and Governance: Codeberg is community-driven, allowing users to participate in decision-making processes and shape the direction of the platform. This democratic approach ensures that the platform evolves in line with the needs and values of its users.

Support for Free and Open Source Software (FOSS): Codeberg is committed to promoting and supporting free and open-source software, providing a home for projects that align with these principles.

Why Bulk Migration Matters

Migrating repositories one by one can be a tedious and time-consuming task, especially if you have numerous projects to transfer. Bulk migration streamlines this process by allowing you to transfer multiple repositories simultaneously, significantly reducing the time and effort required.

Introducing the Migration Script

This is a bash script designed to simplify the migration of repositories from GitHub to Codeberg. It automates the migration process, making it easy to transfer your projects in bulk while preserving their metadata and access permissions.

Key Features

  1. Bulk Migration: The script allows you to migrate multiple repositories from GitHub to Codeberg simultaneously, saving you time and effort.

  2. Customization Options: You can customize various aspects of the migration process, including repository selection and description prefix, to suit your specific requirements.

  3. Error Handling: The script includes error handling mechanisms to handle any migration failures gracefully, ensuring a smooth and reliable migration process.

Preparing the Ground

Before diving into the migration process, you'll need to obtain API keys from GitHub and Codeberg. Here's how you can do it:

Obtaining API Key from GitHub

  1. Visit GitHub Developer Settings: Go to your GitHub account settings and navigate to the "Developer settings" section.

  2. Create a Personal Access Token: Click on "Personal access tokens" and then "Generate new token." Provide a descriptive name for the token and select the desired scopes (e.g., repo for full access to repositories). Click "Generate token" to create the token.

  3. Copy the Token: Once the token is generated, make sure to copy it immediately. GitHub will not display the token again for security reasons.

Obtaining API Key from Codeberg

  1. Access Codeberg Account Settings: Log in to your Codeberg account and navigate to the account settings page.

  2. Generate Personal Access Token: In the settings menu, select "Applications" and then click on "Generate new token." Provide a name for the token and select the necessary scopes (e.g., repo for repository access).

  3. Save the Token: After generating the token, make sure to save it securely. Like GitHub, Codeberg will not display the token again, so it's essential to store it in a safe location.

With your API keys in hand, you're now ready to proceed with the migration process using the "GitHub to Codeberg Bulk Migration Script."

How It Works

Before proceeding with the migration process, it's crucial to ensure that you understand the script's functionality and potential implications. Here's how you can get started:

  1. Download the Script: Begin by downloading the migration script from the following repository:

  2. Read the Script: Once downloaded, take the time to thoroughly read and understand the script (migrate_github_to_codeberg.sh). It's essential never to run a script without comprehending its functionality and potential effects on your system. While the script is provided as a helpful tool, it comes with no warranties, and understanding its behavior is critical for a safe and successful migration. Here's what you'll find in the user configuration section:

# User Configuration:
# --------------------
# GitHub username and personal access token
# GITHUB_USERNAME="YourGitHubUsername"
# GITHUB_TOKEN="YourGitHubToken"
#
# Codeberg username and personal access token
# CODEBERG_USERNAME="YourCodebergUsername"
# CODEBERG_TOKEN="YourCodebergToken"
#
# Define the REPOSITORIES array with repository names you want to migrate
# Leave it blank to migrate all repositories, or create a list of repositories
# if you want to select specific ones.
# REPOSITORIES=(
#     "repository1"
#     "repository2"
#     "repository3"
# )
#
# Custom prefix for description
# DESCRIPTION_PREFIX=""
# or something like:
# DESCRIPTION_PREFIX="[MIRROR] "
  1. Configure User Settings: Open the script in a text editor and navigate to the user configuration section. Here, you'll need to update your GitHub and Codeberg credentials, as well as any other settings according to your preferences.

  2. Review Customization Options: Take advantage of the script's customization options to tailor the migration process to your specific needs. You can define the repositories you want to migrate, specify a description prefix, and adjust other parameters as required.

  3. Install Dependencies: Ensure that the necessary dependencies, such as curl and jq, are installed on your system to facilitate the migration process. You can install these dependencies using your system's package manager.

  4. Run the Script: Once you've reviewed and configured the script to your satisfaction, execute it in your terminal by running ./migrate_github_to_codeberg.sh. Follow the on-screen instructions to initiate the migration process.

  5. Monitor Progress and Review Results: The script will provide real-time updates on the migration progress, allowing you to monitor successful migrations and identify any errors encountered. Once the migration is complete, review the results to ensure that all desired repositories have been successfully migrated to Codeberg.

Some output examples

Migrating some few repositories with the prefix [MIRROR] to the description of the repository.

    ----------------------------------------------
    Welcome to Github to Codeberg Migration Script
    ----------------------------------------------

    User on Github          : LionyxML
    User on Codeberg        : LionyxML
    Using description prefix: [MIRROR] 
    Migrating repo          : aa
    Migrating repo          : dotfiles
    Migrating repo          : flycheck
    Migrating repo          : my_emacs_config

    If you wish to change this, abort and change this script.



    Press ENTER to continue, C-c to abort.


>>> Working...
>>> Migrating: aa... Error! Already exists on Codeberg.
>>> Migrating: flycheck... Success!
>>> Migration complete!

Migrating all repositories.

    Github to Codeberg Migration Script
    ----------------------------------------------

    User on Github          : LionyxML
    User on Codeberg        : LionyxML
    Using description prefix: [MIRROR] 
    Migrating repo          : all

    If you wish to change this, abort and change this script.



    Press ENTER to continue, C-c to abort.


>>> Working...
>>> Migrating: 100_computer_science_concepts... Error! Already exists on Codeberg.
>>> Migrating: 10_design_patterns... Error! Already exists on Codeberg.
>>> Migrating: aa... Error! Already exists on Codeberg.
...

Notice it can fail for one or other repository (eg.: it is already migrated from another script run), but it keeps going until the end.

By following these steps and exercising caution throughout the process, you can safely and efficiently migrate your repositories from GitHub to Codeberg using the provided script. Remember to always read and understand scripts before execution, and proceed with care to ensure a smooth transition.

Limitations

While the script offers a convenient solution for transferring repositories, there are some limitations to be aware of:

  • Repository Quota: Codeberg limits the number of repositories per user to 100 by default. If you have more than 100 repositories to migrate, you'll need to request a higher quota following their instructions. Additionally, Codeberg mirrors repositories, meaning that a repository on Codeberg acts as a mirror of the original repository on GitHub. This may affect certain functionalities, such as repository forks and pull requests.

  • API Changes and Improvements: As with any script utilizing external APIs, there's a possibility that API endpoints or functionalities may change over time. Codeberg may also introduce new features or improvements to their platform, offering better options for migration. It's essential to keep this in mind and periodically review and update the script to align with any changes or enhancements.

  • Local Repository Copies: The migration script only handles the transfer of repository metadata and contents to Codeberg. Your local copies of repositories will remain unaffected by the migration process. After running the script, you'll need to manually add a new remote for each repository pointing to Codeberg and push the changes to both GitHub and Codeberg remotes until you feel confident that the migration is complete.

To add a new remote for a repository and push to both GitHub and Codeberg remotes using SSH, follow these steps:

1 . Navigate to Repository Directory: Open the terminal and navigate to the directory of the repository you want to migrate.

2 . Edit .git/config: Open the .git/config file in a text editor. Add a new remote entry under the [remote "codeberg"] section with the SSH URL of your Codeberg repository. Here's an example of how it might look:

[remote "codeberg"]
   url = git@codeberg.org:YourUsername/YourRepository.git
   fetch = +refs/heads/*:refs/remotes/codeberg/*

3 . Save and Close: Save the changes to the .git/config file and close the text editor.

4 . Push Changes: In the terminal, run the following commands to push changes to both GitHub and Codeberg remotes:

git push origin master  # Push changes to GitHub
git push codeberg master  # Push changes to Codeberg

Of course you could also do it without checking your config with:

git remote add codeberg git@codeberg.org:YourUsername/YourRepository.git

Repeat these steps for each repository you've migrated until you feel confident that the migration process is complete. Or maybe you'll feel in the mood to hack a script to do it 😉.

As one can see, this script provides a solid foundation for repository migration, users are encouraged to customize and enhance it according to their specific use cases and requirements. By leveraging the script's flexibility, users can optimize the migration process to suit their individual needs and preferences.

Deleting API Keys

After completing the migration process, it's essential to delete the API keys you generated for GitHub and Codeberg to maintain security. Follow the respective platforms' instructions to revoke or delete the API keys from your account settings.

Conclusion

The "GitHub to Codeberg Bulk Migration Script" offers a simple and efficient solution for migrating your repositories from GitHub to Codeberg in bulk. By automating the migration process, this script saves you time and effort while ensuring a seamless transition to Codeberg. Whether you're migrating a handful of projects or an extensive portfolio of repositories, this script has got you covered. Say goodbye to manual migration headaches and embrace the convenience of bulk migration with this powerful script.