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:
The (external) URL under which the repository will exposed to the outside world via Nginx Proxy Manager then is:
1 |
https://hobbygit.spdns.de/ilek/pybbg.git |
master
in git repositories, the naming convention in GitLab is main
. This means we cannot push the existing git master
branch into the main
branch of our GitLab project.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:
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:
1 2 |
ilek@i7:/media/ramdisk/pybbg$ git init Reinitialized existing Git repository in /media/ramdisk/pybbg/.git/ |
Next we will have to add and commit everything as our first import:
1 2 |
ilek@i7:/media/ramdisk/pybbg$ git add . ilek@i7:/media/ramdisk/pybbg$ git commit -m "Initial commit before 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:
1 2 3 4 5 |
ilek@i7:/media/ramdisk/pybbg$ git remote -v origin gitolite@zerow:pybbg (fetch) origin gitolite@zerow:pybbg (push) ilek@i7:/media/ramdisk/pybbg$ git remote remove origin ilek@i7:/media/ramdisk/pybbg$ git remote add origin https://hobbygit.spdns.de/ilek/pybbg.git |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
ilek@i7:/media/ramdisk/smartwidgets$ git push -uf origin master Username for 'https://hobbygit.spdns.de': ilek Password for 'https://ilek@hobbygit.spdns.de': Enumerating objects: 78, done. Counting objects: 100% (78/78), done. Delta compression using up to 8 threads Compressing objects: 100% (33/33), done. Writing objects: 100% (78/78), 14.92 KiB | 14.92 MiB/s, done. Total 78 (delta 44), reused 78 (delta 44), pack-reused 0 remote: remote: To create a merge request for master, visit: remote: http://q556.fritz.box/ilek/smartwidgets/-/merge_requests/new?merge_request%5Bsource_branch%5D=master remote: To https://hobbygit.spdns.de/ilek/smartwidgets.git + ce82980...22d40e0 master -> master (forced update) Branch 'master' set up to track remote branch 'master' from 'origin'. |
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.