Last active
July 5, 2019 06:23
-
-
Save kylelemons/a461f2733b82a3504ae40854a4a357c3 to your computer and use it in GitHub Desktop.
A simple shell script to migrate a bunch of local git repositories to GitHub private repos
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 -e | |
TOKEN="YOUR_GITHUB_AUTH_TOKEN_HERE" | |
USERNAME="YOUR_USERNAME" | |
mkdir -p repos published | |
for DIR in *.git; do | |
NAME="${DIR%.git}" | |
CREATE="{\"name\":\"${NAME}\",\"description\":\"Migrated ${NAME} repository\",\"private\":true}" | |
echo "${CREATE}" | |
git clone "${DIR}" "repos/${NAME}" | |
curl \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${TOKEN}" \ | |
-H "User-Agent: ${USERNAME} repo migration uploader" \ | |
-H "Content-Type: application/json" \ | |
-d "${CREATE}" \ | |
https://api.github.com/user/repos | |
( | |
cd "repos/${NAME}" | |
git remote add github "[email protected]:${USERNAME}/${NAME}.git" | |
git push --all github | |
) | |
mv "$DIR" published/ | |
echo "**** $DIR published ****" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment