Migrating to a new Git Host

Ever have to change hosts for all your git repositories? Recently, I had to migrate from a local-only setup to Gitlab.

I cannot emphasize enough how valuable it is to have some form of version control while working, and even better to have it hosted separate from your personal computer.

If, like me, you need to migrate, here are four easy steps to achieve your goal.

Pick your new home and get the address

If you are moving to GitHub, GitLab, etc., go create a new project.

Upon creation, you will be presented with your new repository url (E.g. git@<gitlab.com>:group/project.git). Copy it for use later.

Save your old address

It is wise to keep a record of your current git url.

If you do not know what it is, try either of these commands:

git remote show origin  

(should work if referential integrity is intact)

git config --get remote.origin.url  

(incase referential integrity is broken)

Now that you know your address, save it as a new remote with a memorable name. In my example, I used classic.

git remote add classic git@<old_host>:group/project.git  

Update to your new address

Now you are ready to use the new address as your default remote origin.

git remote set-url origin git@<new_host>:group/project.git  

Now you are good to go!