Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Last active July 5, 2019 06:23
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 kylelemons/a461f2733b82a3504ae40854a4a357c3 to your computer and use it in GitHub Desktop.
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
#!/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 "git@github.com:${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