I have recently migrated private repositories from GitHub to AWS CodeCommit, it would take more times if you are doing manually. So, how did we migrate all of our GitHub repositories automatically at once? Yes, we can do it using simple shell scripts.
Create a file with .sh format and copy the below code and set write (execute) permission,
migrate-github-codecommit.sh
GITHUB_ORG="ORG"
curl --silent -u USERNAME:PASSWORD https://api.github.com/orgs/$GITHUB_ORG/repos?per_page=100 -q | grep "\"name\"" | awk -F': "' '{print $2}' | sed -e 's/",//g' >> ~/codecommit/repository.txt
mkdir ~/github && cd ~/github
echo "start"
cat repository.txt | while read next
echo "Repository Name $next"
do
echo $next
aws codecommit create-repository --repository-name $next --region us-east-1
git clone --mirror git@github.com:$GITHUB_ORG/$next.git
cd ~/gihub/$next.git
git push https://USERNAME:PASSWORD@git-codecommit.us-east-1.amazonaws.com/v1/repos/$next --all
git push https://USERNAME:PASSWORD@git-codecommit.us-east-1.amazonaws.com/v1/repos/$next --tags
sleep 10
aws codecommit update-default-branch --repository-name $next --default-branch-name master --region us-east-1
done
Note: If you have any login credentials for github just includes it.
Execute permission for .sh file, and run this script.
chmod +x migrate-github-codecommit.sh
Testing - If you want to delete all the repositories from github quickly use below script,
while read repo; do
echo $repo
curl -X DELETE -u PASSWORD:PASSWORD https://api.github.com/repos/$GIT_ORG/$repo
done < ~/codecommit/repository.txt
Comments (0)