Last active
August 9, 2023 22:57
-
-
Save chinmaya-n/cff02f1277c811deab2e550f2aad9967 to your computer and use it in GitHub Desktop.
Migrate repos from Bitbucket to Github (only Master branch)
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 | |
# verify for two script params | |
if [ "$#" -ne 2 ]; then | |
echo "Need two arguments." | |
echo "Usage: ./bitbucket_to_github.sh <repo_name> <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=github_user_name | |
API_TOKEN=489_github_api_token_5268 | |
REPO_NAME=$1 | |
BB_URL=$2 | |
echo "" | |
echo "Cloning the repo ..." | |
git clone --bare $BB_URL | |
pushd $REPO_NAME | |
git remote rename origin bitbucket | |
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}' | |
echo "" | |
echo "Pushing to Github ..." | |
git remote add origin git@github.com:$USERNAME/$REPO_NAME.git | |
git push -f origin master | |
git remote rm bitbucket | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Technically not just bitbucket, the repo URL can be any Git server. Feel free to modify this script to make it better. One can also eliminate the repo name input as well, by extracting it from the repo URL.