Skip to content

Instantly share code, notes, and snippets.

@phixion
Last active June 20, 2026 18:00
Show Gist options
  • Select an option

  • Save phixion/742e2f1f6e4458563a84f6943dcc68c3 to your computer and use it in GitHub Desktop.

Select an option

Save phixion/742e2f1f6e4458563a84f6943dcc68c3 to your computer and use it in GitHub Desktop.
migrate to codeberg
#variables
#gh token, scope repo: https://github.com/settings/tokens
#cb token: https://codeberg.org/user/settings/applications
export GH_TOKEN="token"
export CB_TOKEN="token"
export GH_USER="user"
#get gh repos
curl -s -H "Authorization: token $GH_TOKEN" \
"https://api.github.com/user/repos?per_page=100&affiliation=owner" \
| jq -r '.[].name' > repos.txt
#read repos.txt and clode to codeberg
while IFS= read -r REPO; do
if [ -z "$REPO" ]; then continue; fi # Skip empty lines
echo "migrating: $REPO..."
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X 'POST' \
'https://codeberg.org/api/v1/repos/migrate' \
-H 'accept: application/json' \
-H "Authorization: token $CB_TOKEN" \
-H 'Content-Type: application/json' \
-d "{
\"clone_addr\": \"https://github.com/$GH_USER/$REPO.git\",
\"auth_token\": \"$GH_TOKEN\",
\"repo_name\": \"$REPO\",
\"service\": \"github\",
\"mirror\": false,
\"issues\": true,
\"pull_requests\": true,
\"releases\": true,
\"wiki\": true
}")
if [ "$RESPONSE" -eq 201 ]; then
echo "queued migration: $REPO"
else
echo "failed migration: $REPO (HTTP Status: $RESPONSE)"
fi
echo "----------------------------------------"
sleep 2 # Small pause to avoid aggressive rate limiting
done < repos.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment