#!/bin/bash set -euo pipefail read -p "Github repo to clone: " gh read -p "Bitbucket destination: " bb read -p "Github username: " ghu read -p "Bitbucket username: " bbu git clone https://github.com/$ghu/$gh pushd $gh # Fetch all of the remote branches and tags: git fetch origin # View all "old repo" local and remote branches: git branch -a for br in `git branch -a --list | grep -v "\->" | grep "remotes\/origin" | awk -F"/" '{print $3}' | grep -vE "^master$" | sed 's/\#/\\#/'`; d\ o # checkout to create a local copy of all branches to ensure none are missing: git checkout -b $br origin/$br done git remote add new-origin https://$bbu@bitbucket.com/$bbu/$bb git push --all new-origin git push --tags new-origin git remote -v git remote rm origin git remote rename new-origin origin git remote set-url --push origin https://$bbu@bitbucket.com/$bbu/$bb # echo >> .gitignore # git commit -m 'Force remote update' git push -u origin master popd