Created
November 5, 2024 15:38
-
-
Save Deadlyelder/3272b34a1fb9b023b28b4cd613fe6e3a to your computer and use it in GitHub Desktop.
transfer repos between org
This file contains 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
#!/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