Last active
April 7, 2019 06:09
-
-
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/
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
# 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