Skip to content

Instantly share code, notes, and snippets.

@adamwalter
Last active September 10, 2016 15:01
Show Gist options
  • Save adamwalter/ef63ff6ae206b322fd8d7790da0084a4 to your computer and use it in GitHub Desktop.
Save adamwalter/ef63ff6ae206b322fd8d7790da0084a4 to your computer and use it in GitHub Desktop.
Bulk repo migration from GitHub to Bitbucket
#!/bin/bash -e
# Usage: ./bitbucket-migrate.sh repos.txt
#
# repos.txt should have one repository per line.
echo "Reading $1"
while read line
do
repo=$line
key=$(LC_CTYPE=C tr -dc A-Z < /dev/urandom | head -c 2 | xargs)
echo "###"
echo "Processing $repo"
git clone --bare git@github.com:USERNAME/$repo.git
cd $repo.git
echo "Creating repo in Bitbucket"
curl -H "Content-Type: application/json" -X POST -d '{"name": "'$line'", "key": "'$key'", "is_private": true}' --user "username:password" https://api.bitbucket.org/2.0/teams/USERNAME/projects/
curl -H "Content-Type: application/json" -X POST -d '{"name": "'$line'", "is_private": true, "project": {"key": "'$key'"}}' --user "username:password" https://api.bitbucket.org/2.0/repositories/USERNAME/$line/
echo "Pushing mirror to bitbucket"
git push --mirror git@bitbucket.org:USERNAME/$repo.git
cd ..
echo "Removing $repo.git"
rm -rf "$repo.git"
echo "Waiting 5 seconds"
echo "###"
sleep 5;
done < $1;
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment