Skip to content

Instantly share code, notes, and snippets.

@ilovett
Created March 27, 2019 14:20
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 ilovett/db8563730ac49de43a6cd81825f77015 to your computer and use it in GitHub Desktop.
Save ilovett/db8563730ac49de43a6cd81825f77015 to your computer and use it in GitHub Desktop.
migrate bitbucket to github private user repo

stolen and modified from https://gist.github.com/leosoto/ebd8554635d0e5f4346d9b57da3c9f5d

this version is for your own private user repo instead of organizations also uses personal access token instead of user/pass/2fa

# install bitbucket cli on mac os
sudo easy_install pip
sudo pip install bitbucket-cli

# make a github personal access token with private repo control

export GH_USERNAME=<your github username>
export GH_PERSONAL_ACCESS_TOKEN=<your github personal access token>
export BB_USERNAME=<your bitbucket username>
export BB_PASSWORD=<your bitbucket password>

# run the script
./bb2gh.sh
#!/bin/bash
set -e
repos=$(bb list -u $BB_USERNAME -p $BB_PASSWORD --private | grep $BB_USERNAME | cut -d' ' -f3 | cut -d'/' -f2)
for repo in $repos; do
echo
echo "* Processing $repo..."
echo
git clone --bare git@bitbucket.org:$BB_USERNAME/$repo.git || ls -al | grep $repo
cd $repo.git
echo
echo "* $repo cloned, now creating on github..."
echo
curl -H "Authorization: token $GH_PERSONAL_ACCESS_TOKEN" https://api.github.com/user/repos -d "{\"name\": \"$repo\", \"private\": true}"
echo
echo "* mirroring $repo to github..."
echo
git push --mirror git@github.com:$GH_USERNAME/$repo.git && \
bb delete -u $BB_USERNAME -p $BB_PASSWORD --owner $BB_USERNAME $repo
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment