-
-
Save austinjp/d5436540ffeba5aef80c8c77c7f2b29c to your computer and use it in GitHub Desktop.
Moving git repository and all its branches, tags to a new remote repository keeping commits history
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment