Created
February 20, 2025 08:56
-
-
Save joaomagfreitas/2bba41028d0989ee47ebc209cf86643a to your computer and use it in GitHub Desktop.
Move personal forks to org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Set your GitHub username and token | |
| GITHUB_USER="freitzzz" | |
| GITHUB_TOKEN="" | |
| ORG="fforks" | |
| # Get a list of all forked repositories | |
| forks=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
| "https://api.github.com/users/$GITHUB_USER/repos?per_page=100" | jq -r '.[] | select(.fork) | .name') | |
| # Loop through each fork and transfer ownership | |
| for repo in $forks; do | |
| echo "Transferring $repo to $ORG..." | |
| read -p "Confirm? (y/n): " confirm | |
| if [[ "$confirm" =~ ^[Yy]$ ]]; then | |
| echo "Transferring $repo to $ORG..." | |
| response=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ | |
| -H "Authorization: token $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -d "{\"new_owner\": \"$ORG\"}" \ | |
| "https://api.github.com/repos/$GITHUB_USER/$repo/transfer") | |
| if [[ "$response" == "202" ]]; then | |
| echo "✅ Successfully transferred $repo to $ORG" | |
| else | |
| echo "❌ Failed to transfer $repo (HTTP $response)" | |
| fi | |
| else | |
| echo "⏩ Skipped $repo" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment