{"id":1810,"date":"2023-04-05T20:18:50","date_gmt":"2023-04-05T18:18:50","guid":{"rendered":"https:\/\/hobbykeller.spdns.de\/?p=1810"},"modified":"2023-04-05T22:01:40","modified_gmt":"2023-04-05T20:01:40","slug":"importing-a-local-git-repository-into-gitlab","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=1810","title":{"rendered":"Importing a local git repository into GitLab"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Before decommissioning my gitolite server, which I had in production <a href=\"https:\/\/hobbykeller.spdns.de\/?p=718\" data-type=\"post\" data-id=\"718\">since 2015<\/a>, I cloned all repositories to a local machine. The tricky question now is: How can I reimport these repositories to my new GitLab server?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following instructions,  are based on a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.theserverside.com\/blog\/Coffee-Talk-Java-News-Stories-and-Opinions\/How-to-add-and-push-an-existing-project-to-GitLab\" target=\"_blank\">blog that appears on theserverside.com<\/a>. For demonstration purposes, we assume that we have a local clone of a gitolite repository which is called <code>pybbg<\/code>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Setp 1: Create repo in GitLab<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Start by creating a new repository in GitLab. I used the current repo name (without the .git extension) as the GitLab project slug:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-04-14-37-05.png\"><img loading=\"lazy\" decoding=\"async\" width=\"828\" height=\"571\" src=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-04-14-37-05.png\" alt=\"\" class=\"wp-image-1812\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-04-14-37-05.png 828w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-04-14-37-05-300x207.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-04-14-37-05-768x530.png 768w\" sizes=\"auto, (max-width: 828px) 100vw, 828px\" \/><\/a><figcaption class=\"wp-element-caption\">Creating a blank GitLab project to which the gitolite project will be imported<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The (external) URL under which the repository will exposed to the outside world via Nginx Proxy Manager then is:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" title=\"External URL of newly created project\">https:\/\/hobbygit.spdns.de\/ilek\/pybbg.git<\/pre><\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-primary\" role=\"alert\">While the name for the default branch is <code>master<\/code> in git repositories, the naming convention in GitLab is <code>main<\/code>. This means we cannot push the existing git <code>master<\/code> branch into the <code>main<\/code> branch of our GitLab project.<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">\u00d7<\/span><\/button><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">I found it the easiest way to work around this problem to create a <code>master<\/code> branch in the GitLab project, then push the repository to the <code>master<\/code> branch and finally merge the <code>master<\/code> branch into GitLab&#8217;s <code>main<\/code> branch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a master branch in your project, click <strong>Repository<\/strong> in the navigation bar on the lhs, click <strong>Branches<\/strong> and then hit the <strong>New Branch<\/strong> button:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"220\" src=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42-1024x220.png\" alt=\"\" class=\"wp-image-1813\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42-1024x220.png 1024w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42-300x65.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42-768x165.png 768w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-05-19-43-42.png 1255w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Setting up a new branch for a repository<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After entering <code>master<\/code> as the name for the new branch and hitting the <strong>Create Branch<\/strong> button, you will be directed to the Project view of the <code>master<\/code> branch. In the top section of the main window a <strong>Create merge request<\/strong> button will show up. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Step 2: Push the local repo to the GitLab server<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">On your workstation cd to the folder holding the repo and reinit the git repository:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" title=\"Reinitializing your local git repository\">ilek@i7:\/media\/ramdisk\/pybbg$ git init\nReinitialized existing Git repository in \/media\/ramdisk\/pybbg\/.git\/<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Next we will have to add and commit everything as our first import:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \">ilek@i7:\/media\/ramdisk\/pybbg$ git add .\nilek@i7:\/media\/ramdisk\/pybbg$ git commit -m \"Initial commit before import\"<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" >ilek@i7:\/media\/ramdisk\/pybbg$ git remote -v\norigin\tgitolite@zerow:pybbg (fetch)\norigin\tgitolite@zerow:pybbg (push)\nilek@i7:\/media\/ramdisk\/pybbg$ git remote remove origin\nilek@i7:\/media\/ramdisk\/pybbg$ git remote add origin https:\/\/hobbygit.spdns.de\/ilek\/pybbg.git<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Now we should be ready to push the repository (don&#8217;t forget the <code>-uf<\/code> flag because otherwise GitLab will refuse the push on the ground that the remote contains work which is not included on your local.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab will ask you for your credentials &#8211; which are the ones you would use to log into the website.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" >ilek@i7:\/media\/ramdisk\/smartwidgets$ git push -uf origin master\nUsername for 'https:\/\/hobbygit.spdns.de': ilek\nPassword for 'https:\/\/ilek@hobbygit.spdns.de': \nEnumerating objects: 78, done.\nCounting objects: 100% (78\/78), done.\nDelta compression using up to 8 threads\nCompressing objects: 100% (33\/33), done.\nWriting objects: 100% (78\/78), 14.92 KiB | 14.92 MiB\/s, done.\nTotal 78 (delta 44), reused 78 (delta 44), pack-reused 0\nremote: \nremote: To create a merge request for master, visit:\nremote:   http:\/\/q556.fritz.box\/ilek\/smartwidgets\/-\/merge_requests\/new?merge_request%5Bsource_branch%5D=master\nremote: \nTo https:\/\/hobbygit.spdns.de\/ilek\/smartwidgets.git\n + ce82980...22d40e0 master -&gt; master (forced update)\nBranch 'master' set up to track remote branch 'master' from 'origin'.\n<\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">Step 3: Merging the master branch into the main branch<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">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 <code>Import from gitolite<\/code> as the title of the request and <code>Revert to GitLab main branch<\/code> as a Description. Then scroll down to click <strong>Create the merge request<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After some internal rumbling, GitLab directs you to a new page that says Ready to merge!. Just hit the blue <strong>Merge<\/strong> button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s all, your gitolite repo should now be completely imported into GitLab.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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<span class=\"more-button\"><a href=\"https:\/\/hobbykeller.spdns.de\/?p=1810\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Importing a local git repository into GitLab<\/span><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1810","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1810"}],"version-history":[{"count":4,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1810\/revisions"}],"predecessor-version":[{"id":1816,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1810\/revisions\/1816"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}