Migrate a repository with all its commits and all its branches
For reasons of life I have had to move repositories from one place to another. Regardless of whether Origin / remote is, this guide will help you (they are my tip notes). It has helped me to migrate from Github to Bitbucket, from Bitbucket to Github I have no doubt that it will work in Azure Repos, Gitlab or GCP repositories.
1. Create the new repository
The important thing to do either on github or on bitbucket is not to include any files (disable the readme and not put the gitignore)
2. Clone your base repository
From a terminal clone the repository you need to migrate
git clone https://USER@bitbucket.org/USER/PROYECT_1.git
3. Change the Origin
Indicate that the repository in your git files will change to another origin
cd PROYECTO/
git remote set-url origin git@github.com:USER/PROYECT_2.git
4. Push your code
Push the code with all its commits, branches, tags, etc
git push git@github.com:USER/PROYECT_2.git — tags “refs/remotes/origin/*:refs/heads/*”
If you only want to push the master branch
git push -u origin master
Bonus
You will need to put your ssh keys both in the origin and the remote. To have your key registrered and not have problems when cloning or pushing code.
If you use linux and you haven’t changed the default path , use this code
cat ~/.ssh/id_rsa.pub
I hope it works for you as it does for me.