Skip to content

Instantly share code, notes, and snippets.

@lionello
Last active June 12, 2024 22:45
Show Gist options
  • Save lionello/a7e4ad3ba72c117a35de05f6735551d7 to your computer and use it in GitHub Desktop.
Save lionello/a7e4ad3ba72c117a35de05f6735551d7 to your computer and use it in GitHub Desktop.
Shell script to bulk-transfer repositories from one org to another
#!/usr/bin/env bash
set -e # Exit on error
ORG=DefangLabs
OWNER=$ORG
NEW_OWNER=DefangSamples
TOKEN=ghp_… # REPLACE
repos=$(curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/$ORG/repos?type=public&per_page=100" | jq -r '.[] | select(.is_template == true) | .name')
for REPO in $repos; do
echo "Moving $REPO to $NEW_OWNER"
curl -sL \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$OWNER/$REPO/transfer \
-d "{\"new_owner\":\"$NEW_OWNER\"}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment