Skip to content

Instantly share code, notes, and snippets.

@rkennesson
Forked from jbdelhommeau/gitA2gitB.sh
Created May 29, 2017 04:31
Show Gist options
  • Save rkennesson/f6a2383ceb57fb84e381fad0d2628c3d to your computer and use it in GitHub Desktop.
Save rkennesson/f6a2383ceb57fb84e381fad0d2628c3d to your computer and use it in GitHub Desktop.
Migrate existing respositories in hub A to Github.
#!/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 "git@github.com:$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