Migrating From GitHub To Codeberg

I found this script and I've been using it to migrate my repos from GitHub to Codeberg.

#!/bin/bash
# migrate-repos.sh — migrate a list of repos from GitHub to Codeberg

CODEBERG_TOKEN="your_codeberg_token"
GITHUB_TOKEN="your_github_token"
CODEBERG_USER="yourname"
GITHUB_USER="yourname"

# list your repos, one per line
REPOS=(
  "project-alpha"
  "dotfiles"
  "cool-library"
)

for repo in "${REPOS[@]}"; do
  echo "Migrating $repo..."
  curl -s -X POST "https://codeberg.org/api/v1/repos/migrate" \
    -H "Authorization: token $CODEBERG_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
      \"clone_addr\": \"https://github.com/$GITHUB_USER/$repo.git\",
      \"repo_name\": \"$repo\",
      \"repo_owner\": \"$CODEBERG_USER\",
      \"service\": \"github\",
      \"auth_token\": \"$GITHUB_TOKEN\",
      \"mirror\": false,
      \"issues\": true,
      \"labels\": true,
      \"releases\": true
    }"
  echo "Done. Check https://codeberg.org/$CODEBERG_USER/$repo"
  sleep 5  # be nice to the API
done

To get this working you just need to add it to a file, change the values to suit your needs, then set that file to be executable (assuming you are on Linux).

chmod +x codeberg.sh

You can now run this by running the command like this.

./codeberg.sh

This works for organisations as well, you just need to make sure your keys are set up correctly and change the "yourname" in the above script to be the organisation name.

This was taken from https://dev.to/alanwest/how-to-actually-migrate-from-github-to-codeberg-without-losing-your-mind-33bf. Alan recommends migrating 2-3 repos a day, checking that everything is good and moving on. Thanks for sharing this Alan!

Add new comment

The content of this field is kept private and will not be shown publicly.