Skip to content

Instantly share code, notes, and snippets.

@mhulse
Last active January 11, 2019 07:34
Show Gist options
  • Select an option

  • Save mhulse/6e32f1a5b403ec8438186f52e9bfc3c6 to your computer and use it in GitHub Desktop.

Select an option

Save mhulse/6e32f1a5b403ec8438186f52e9bfc3c6 to your computer and use it in GitHub Desktop.

Revisions

  1. mhulse revised this gist Jan 11, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions xfer-repos-from-bitbucket-to-github.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/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
  2. mhulse created this gist Jan 11, 2019.
    32 changes: 32 additions & 0 deletions xfer-repos-from-bitbucket-to-github.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/env bash

    # This script assumes you have your ssh keys setup for Bitbucket and GitHub.
    # 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