Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save apristen/95f550b7bf6e248103be2cb6637a746f to your computer and use it in GitHub Desktop.
Save apristen/95f550b7bf6e248103be2cb6637a746f to your computer and use it in GitHub Desktop.
How to move repo from one git to another with all branches and commits, for example from Bitbucket to GitHub.
# see https://www.devopsschool.com/blog/how-to-move-repository-from-bitbucket-to-github-with-all-branches-and-commits/
# see https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
# git clone user@bitbucket.org:source_project_name/source_repo.git # for SSH
git clone https://user@bitbucket.org/source_project_name/source_repo.git # for HTTPS
cd source_repo
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
# all source repo should be cloned totally at this point :-)
# git remote add upstream user@github.com:destination_project_name/destination_repo.git # for SSH
git remote add upstream https://github.com/destination_project_name/destination_repo.git # for HTTPS
git push upstream --all
git push --tags upstream
git remote set-url origin user@github.com:destination_project_name/destination_repo.git # for SSH
# git remote set-url origin https://github.com/destination_project_name/destination_repo.git # for HTTPS
git push --mirror
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment