Created
November 28, 2020 21:29
-
-
Save benjaminoakes/9943a9c3f73b2a9bae3dce091ab745ac to your computer and use it in GitHub Desktop.
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 | |
# Based on https://gist.githubusercontent.com/chinmaya-n/cff02f1277c811deab2e550f2aad9967/raw/5d5511b6b61cb643f207f302fd370522e06948fd/bitbucket_to_github.sh | |
# Slightly manual but better than no automation | |
set -o errexit | |
# verify for two script params | |
if [ "$#" -ne 1 ]; then | |
echo "Need two arguments." | |
echo "Usage: ./bitbucket_to_github.sh <bitbucket_url>" | |
echo "" | |
echo "Prerequisits:" | |
echo "* Public Key authentication for both Github & Bitbucket already setup." | |
echo "* Update this script with your Github Username & API Token." | |
exit 1 | |
fi | |
USERNAME=you | |
API_TOKEN='yourtoken' | |
BB_URL=$1 | |
REPO_NAME=$(basename "$BB_URL" .git) | |
echo "" | |
echo "Cloning the repo ..." | |
git clone --mirror $BB_URL $REPO_NAME | |
pushd $REPO_NAME | |
echo "" | |
echo "Create repo: $REPO_NAME in github ..." | |
curl --request POST \ | |
--url https://api.github.com/user/repos \ | |
--user $USERNAME:$API_TOKEN \ | |
--header 'cache-control: no-cache' \ | |
--header 'content-type: application/json' \ | |
--data '{"name": "'"$REPO_NAME"'", "private": true}' | |
printf "[Press enter to continue]" | |
read | |
echo "" | |
echo "Pushing to Github ..." | |
git remote add github [email protected]:$USERNAME/$REPO_NAME.git | |
git push --mirror github | |
printf "Archive at https://github.com/$USERNAME/$REPO_NAME/settings\n" | |
printf "Delete from https://bitbucket.org/$USERNAME/$REPO_NAME/admin\n" | |
printf "[Press enter to delete from local]" | |
read | |
popd | |
rm -rf "$REPO_NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment