Skip to content

Instantly share code, notes, and snippets.

@thundergolfer
Last active April 7, 2019 06:09
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 thundergolfer/8165e4534d0255418e7676ce37c09e11 to your computer and use it in GitHub Desktop.
Save thundergolfer/8165e4534d0255418e7676ce37c09e11 to your computer and use it in GitHub Desktop.
Move a Github repository from your account to an organisation. Credit to: https://www.codesections.com/blog/cleaning-github-with-a-simple-bash-script/
# Inspired by https://www.codesections.com/blog/cleaning-github-with-a-simple-bash-script/ I decided to
# take multi-organisation approach to organise my Github repositories.
#
# This script allows for quickly transferring a repository in your account to a Github
# organisation you control.
#
# Note: Private repositories must be made public before they can be moved to a 'free-tier' Organisation.
#
# Usage: ./move-repos.sh <REPO NAME> <NEW ORG>
# Note: You probably want to change this
DEFAULT_USERNAME="thundergolfer"
USERNAME="${USERNAME:-$DEFAULT_USERNAME}"
USAGE="./move-repos.sh <REPO> <NEW_ORG>"
if [[ -z "${GITHUB_OAUTH_ACCESS_TOKEN}" ]]; then
echo "Must set GITHUB_OAUTH_ACCESS_TOKEN"
exit 1
fi
if [[ -z "${1}" ]]; then
echo ${USAGE}
exit 1
fi
REPO=${1}
if [[ -z "${2}" ]]; then
echo ${USAGE}
exit 1
fi
NEW_ORG=${2}
curl -H "Authorization: token ${GITHUB_OAUTH_ACCESS_TOKEN}" \
-H "Accept: application/vnd.github.nightshade-preview+json" \
-H "Content-Type: application/json" \
-X POST https://api.github.com/repos/${USERNAME}/${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