Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script to transfer multiple repos from Bitbucket to GitHub (or vice versa). Inspired by https://stackoverflow.com/a/21260628/922323
#!/usr/bin/env bash
# This script assumes you have your ssh keys setup for Bitbucket and GitHub.
# It also assumes you have created the repos on GitHub already and the URL slugs are an exact match.
# Also, this script will barf if you try to transfer an empty repo.
# Note that this code does not transfer wikis, downloads or issues.
# Also note, you may have to turn on QOS upload speed limiting so your router
# doesn’t freak out; I limited my upload bandwidth to 2Mbps.
# Don’t forget to `chmod u+x <this file>.sh` in order to execute it via `./<this file>.sh`.
declare -r bitbucket_user=
declare -r github_user=
declare -r xfer_from=bitbucket.org
declare -r xfer_to=github.com
# Explicitly declare a variable (this is better than implicit):
declare -a repos=(
"foo"
"baz"
"bar"
"other"
)
for i in "${repos[@]}"; do
echo Transfering repo: "$i"
git clone --bare git@${xfer_from}:${bitbucket_user}/${i}.git
cd ${i}.git || exit
git push --mirror git@${xfer_to}:${github_user}/${i}.git
cd - || exit
done
# Gracefully Exit program:
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.