Skip to content

Instantly share code, notes, and snippets.

@Deadlyelder
Created November 5, 2024 15:38
Show Gist options
  • Save Deadlyelder/3272b34a1fb9b023b28b4cd613fe6e3a to your computer and use it in GitHub Desktop.
Save Deadlyelder/3272b34a1fb9b023b28b4cd613fe6e3a to your computer and use it in GitHub Desktop.
transfer repos between org
#!/bin/bash
# Set variables
OLD_ORG="" # Source organization
NEW_ORG="" # Destination organization
GITHUB_TOKEN="" # GitHub token with admin repo permissions (Not a PAT)
API_VERSION="2022-11-28" # GitHub API version (verify in doc)
repos=$(curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: ${API_VERSION}" \
https://api.github.com/orgs/${OLD_ORG}/repos | jq -r '.[].name')
if ! command -v jq &> /dev/null; then
echo "The 'jq' command is required but not installed. Please install 'jq' and try again."
exit 1
fi
for repo in $repos; do
echo "Transferring repo: ${repo} to ${NEW_ORG}"
# API call to transfer the repository
curl -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: ${API_VERSION}" \
https://api.github.com/repos/${OLD_ORG}/${repo}/transfer \
-d "{\"new_owner\":\"${NEW_ORG}\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment