Skip to content

Instantly share code, notes, and snippets.

@rahulkj
Created June 27, 2019 10:11
Show Gist options
  • Save rahulkj/71db9bb451f578840b4d062cc0347be7 to your computer and use it in GitHub Desktop.
Save rahulkj/71db9bb451f578840b4d062cc0347be7 to your computer and use it in GitHub Desktop.
Script to transfer all the git repos from one org to another
#!/bin/bash -x
export GIT_USER=
export GIT_TOKEN=
export ORG_NAME=
export NEW_ORG_NAME=
export OUTPUT_FILE=repos.json
rm -rf $OUTPUT_FILE
curl -u $GIT_USER:$GIT_TOKEN "https://api.github.com/users/$ORG_NAME/repos" -s > $OUTPUT_FILE
REPO_NAMES=$(cat $OUTPUT_FILE | jq -r '.[] | .name')
for REPO in $REPO_NAMES
do
echo "repo is: $REPO"
curl -u $GIT_USER:$GIT_TOKEN "https://api.github.com/repos/$ORG_NAME/$REPO/transfer" \
-X POST -d '{"new_owner": "'"$NEW_ORG_NAME"'"}' \
-H "Accept: application/vnd.github.nightshade-preview+json"
done
rm -rf $OUTPUT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment