Move your Git repo from one remote repository to another

Recently I needed to move one of my projects from Gitlab to Github. If you also want to do something similar here is a guide for you. Note that although I am using Gitlab and Github as an example, you can do this for moving your remote repository from any provider to any other or from any remote repo to another.

Technically we are actually not “moving” anything. All we are doing is to change where our repository’s origin points to.

First we start by looking at the remotes on our local git repo:

$ git remote -v
origin  https://gitlab.com/my_username/my_repo.git (fetch)
origin  https://gitlab.com/my_username/my_repo.git (push)

This means that we have a remote called origin that we can pull (fetch) from and push to. In this example origin points to a repo on Gitlab. Using the following command we tell origin to point to a new repo on Github instead:

$ git remote set-url origin https://github.com/my_username/my_new_repo.git

That’s it! If we list the remotes again we will see that the new address is set:

$ git remote -v
origin  https://github.com/my_username/my_new_repo.git (fetch)
origin  https://github.com/my_username/my_new_repo.git (push)

Now we can do a push and we are good to go!

Subscribe via RSS