Moving a Gitlab Repo

If you want to move a repository from one Gitlab instance to one on another server, the following works well (make sure you create an empty repo on the new Gitlab instance, and make sure the name is different):

git clone git@my.gitlab-server.com/someRepo.git someRepo
cd someRepo
git remote add someRepo2 git@my.other-gitlab.com/someRepo2.git
git push someRepo2 master
git remote set-url someRepo2 git@my.other-gitlab.com/someRepo2.git
git remote set-url origin git@my.other-gitlab.com/someRepo2.git

Explanation:

First, we make sure we create the new empty repo “someRepo2” on the new Gitlab server.

Then we clone our repo “someRepo” from our old Gitlab instance. Once complete, change to the directory, and add the new repo name and URL . Next we will push the contents of the repo to the new server under the new repo name.

In this case, we want to actually change the origin of the repo, so we set the URL of the new Gitlab server, and finally explicitly change “origin” to the new location.

I found that using the same name for the repositories on both instances generated errors, so I would recommend using different names. There’s probably a way around this, but I didn’t have the patience to figure it out.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.