Site Overlay

Importing a local git repository into GitLab

Before decommissioning my gitolite server, which I had in production since 2015, I cloned all repositories to a local machine. The tricky question now is: How can I reimport these repositories to my new GitLab server?

The following instructions, are based on a blog that appears on theserverside.com. For demonstration purposes, we assume that we have a local clone of a gitolite repository which is called pybbg.

Setp 1: Create repo in GitLab

Start by creating a new repository in GitLab. I used the current repo name (without the .git extension) as the GitLab project slug:

Creating a blank GitLab project to which the gitolite project will be imported

The (external) URL under which the repository will exposed to the outside world via Nginx Proxy Manager then is:

I found it the easiest way to work around this problem to create a master branch in the GitLab project, then push the repository to the master branch and finally merge the master branch into GitLab’s main branch.

To create a master branch in your project, click Repository in the navigation bar on the lhs, click Branches and then hit the New Branch button:

Setting up a new branch for a repository

After entering master as the name for the new branch and hitting the Create Branch button, you will be directed to the Project view of the master branch. In the top section of the main window a Create merge request button will show up.

Leave the window as it is and switch over to the console of your workstation. We are now ready to push our local git repository to the GitLab server.

Step 2: Push the local repo to the GitLab server

On your workstation cd to the folder holding the repo and reinit the git repository:

Next we will have to add and commit everything as our first import:

Next we add the remote which is the project URL on our github server. Check if the remote is already existing and delete it to recreate it:

Now we should be ready to push the repository (don’t forget the -uf flag because otherwise GitLab will refuse the push on the ground that the remote contains work which is not included on your local.

GitLab will ask you for your credentials – which are the ones you would use to log into the website.

Step 3: Merging the master branch into the main branch

Switch back to your GitLab browser window and click Create merge request. Basically you can leave all settings as they are. In particular, there is no need to choose an Assignee, Reviewer etc. I just set Import from gitolite as the title of the request and Revert to GitLab main branch as a Description. Then scroll down to click Create the merge request.

After some internal rumbling, GitLab directs you to a new page that says Ready to merge!. Just hit the blue Merge button.

That’s all, your gitolite repo should now be completely imported into GitLab.