Skip to content

Instantly share code, notes, and snippets.

@Ran-Xing
Created May 5, 2022 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ran-Xing/36dd9f85f4e64ebea3a6a59947165b2d to your computer and use it in GitHub Desktop.
Save Ran-Xing/36dd9f85f4e64ebea3a6a59947165b2d to your computer and use it in GitHub Desktop.
Transfer Github Repo To Other Owner
#!/usr/bin/env bash
#set -ex
Owner="$1"
GITHUB_API_TOKEN="$2"
NewOwner=$3
REPOS="$(
curl -s -H "Authorization: token $GITHUB_API_TOKEN" \
"https://api.github.com/users/${Owner}/repos?per_page=1000" | jq -r '.[].name' | sort
)"
TeamID="$(
curl -s -H "Authorization: token $GITHUB_API_TOKEN" \
"https://api.github.com/orgs/${NewOwner}" | jq -r '.id'
)"
for i in $REPOS ;
do
echo "$i : $(curl \
-s \
-X POST \
-H "Authorization: token ${GITHUB_API_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$Owner/$i/transfer" \
-d '{"new_owner":"'"${NewOwner}"'","team_ids":['"${TeamID}"']}' \
| jq -r '.id')"
done
@Ran-Xing
Copy link
Author

Ran-Xing commented May 5, 2022

./TransferGithub.sh [Owner] [GITHUB_API_TOKEN][NewOwner]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment