Created
June 23, 2016 12:54
-
-
Save jbdelhommeau/1c04ab7effb240b42d3431f549a8014a to your computer and use it in GitHub Desktop.
Migrate existing respositories in hub A to Github.
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 | |
repos="my-repo1 | |
my-repo2 | |
my-repo3" | |
# Git A source can be github, gitlab | |
GIT_A='gitlab.com' | |
GIT_A_ORGANIZATION='miahou' | |
# GIT B is github | |
GIT_B_USER='octocat' | |
GIT_B_PASSWORD='****' | |
GIT_B_ORGANIZATION='poulpe' | |
for repo in $repos | |
do | |
echo "------------------" | |
echo "1- Creating respositories to github: $repo" | |
# Show github api documentation for more options | |
# https://developer.github.com/v3/repos/#input | |
statutCode=$(curl --write-out %{http_code} --silent --output /dev/null --user "$GIT_B_USER:$GIT_B_PASSWORD" \ | |
--data '{ | |
"name": "'$repo'", | |
"private": false, | |
"has_issues": true, | |
"has_wiki": true, | |
"has_downloads": true | |
}' \ | |
"https://api.github.com/orgs/$GIT_B_ORGANIZATION/repos") | |
if [ $statutCode -gt 200 ] && [ $statutCode != 422 ] ; then | |
echo "Error : Cannot create repository. Check your Github identity" | |
continue | |
fi | |
if [ $statutCode == 422 ] ; then | |
echo "Repository $repo already exists" | |
fi | |
echo "2- Create local mirror of repository A at copy" | |
git clone --mirror "git@$GIT_A:$GIT_A_ORGANIZATION/$repo.git" | |
cd "$repo.git" | |
echo "3- Push repository on his new place B" | |
git push --no-verify --mirror "[email protected]:$GIT_B_ORGANIZATION/$repo.git" | |
cd ../ | |
echo "Respository migration done !" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment