Skip to content

Instantly share code, notes, and snippets.

@BrocksiNet
Last active July 26, 2019 14:22
Show Gist options
  • Save BrocksiNet/ffd2ec437ed4ffdcfed08332e80a5157 to your computer and use it in GitHub Desktop.
Save BrocksiNet/ffd2ec437ed4ffdcfed08332e80a5157 to your computer and use it in GitHub Desktop.
Shell-Script to move repositories from bitbucket to github
#!/bin/bash
set -e
# Shell script to move repos from bitbucket to github
ä
# use the command like this:
# ./bitbucket-to-github.sh -org="organization" -ghu="github-username" -ghp="github-password" -bbu="bitbucket-username" -bbp="bitbucket-password"
for i in "$@"
do
case $i in
-org=*|--organization=*)
ORGANIZATION="${i#*=}"
shift # past argument=value
;;
-ghu=*|--gh_username=*)
GH_USERNAME="${i#*=}"
shift # past argument=value
;;
-ghp=*|--gh_password=*)
GH_PASSWORD="${i#*=}"
shift # past argument=value
;;
-bbu=*|--bb_username=*)
BB_USERNAME="${i#*=}"
shift # past argument=value
;;
-bbp=*|--bb_password=*)
BB_PASSWORD="${i#*=}"
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
echo "ORGANIZATION = ${ORGANIZATION}"
# you can add a array of repos here ... just the name without organisation, slash and .git
repos=( "magento-test1" "magento-test2" )
for repo in "${repos[@]}"; do
echo
echo "* Processing ${ORGANIZATION}/${repo}.git ..."
echo
git clone --bare git@bitbucket.org:${ORGANIZATION}/${repo}.git
cd ${repo}.git
echo
echo "* ${repo} cloned, now creating on github..."
echo
curl -u $GH_USERNAME:$GH_PASSWORD https://api.github.com/orgs/${ORGANIZATION}/repos -d "{\"name\": \"$repo\", \"private\": true}"
echo
echo "* mirroring ${repo} to github..."
echo
git push --mirror git@github.com:${ORGANIZATION}/${repo}.git
echo
echo "${repo} pushed to github :-)"
echo
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment