<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/migrating-from-github-to-gitlab-with-rstudio-tutorial/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://shiring.github.io/tutorials/2017/09/04/migrating_github_gitlab"> Shirin's playgRound</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>GitHub vs. GitLab</h2>
<p>Git is a distributed implementation of version control. Many people have written very eloquently about why it is a good idea to use version control, not only if you collaborate in a team but also if you work on your own; one example is <a rel="nofollow" href="https://support.rstudio.com/hc/en-us/articles/200532077?version=1.0.153&mode=desktop" target="_blank">this article from RStudio’s Support pages</a>.</p>
<p>In short, its main feature is that version control allows you to keep track of the changes you make to your code. It will also keep a history of all the changes you have made in the past and allows you to go back to specific versions if you made a major mistake. And Git makes collaborating on the same code very easy.</p>
<p>Most R packages are also hosted on <a rel="nofollow" href="https://github.com/" target="_blank">GitHub</a>. You can check out their R code in the repositories if you want to get a deeper understanding of the functions, you can install the latest development versions of packages or install packages that are not on CRAN. The issue tracker function of GitHub also makes it easy to report and respond to issues/problems with your code.</p>
<h3>Why would you want to leave GitHub?</h3>
<p>Public repositories are free on GitHub but you need to pay for private repos (if you are a student or work in academia, you <a rel="nofollow" href="https://education.github.com/discount_requests/new" target="_blank">get private repos for free</a>). Since I switched from academia to industry lately and no longer fulfil these criteria, all my private repos would have to be switched to public in the future. Here, GitLab is a great alternative!</p>
<p><a rel="nofollow" href="https://gitlab.com/" target="_blank">GitLab</a> offers very similar functionalities as GitHub. There are <a rel="nofollow" href="https://www.slant.co/versus/532/4860/~github_vs_gitlab" target="_blank">many pros and cons for using GitHub versus GitLab</a> but for me, the selling point was that GitLab offers unlimited private projects and collaborators in its free plan.</p>
<p></p>
<h1>Tutorial</h1>
<p>Migrating from GitHub to <a rel="nofollow" href="https://gitlab.com/" target="_blank">GitLab</a> with RStudio is very easy! Here, I will show how I migrated my GitHub repositories of R projects, that I work with from within RStudio, to GitLab.</p>
<p><img alt="" src="https://i1.wp.com/shiring.github.io/tutorials/2017/09/04/GitLab_logo.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Beware, that ALL code snippets below show Terminal code (they are NOT from the R console)!</p>
<p></p>
<h2>Migrating existing repositories</h2>
<p>You first need to set up your GitLab account (you can login with your GitHub account) and connect your old GitHub account. Under <a rel="nofollow" href="https://gitlab.com/profile/account" target="_blank">Settings &amp;Account</a>, you will find “Social sign-in”; here click on “Connect” next to the GitHub symbol (if you signed in with your GitHub account, it will already be connected).</p>
<p>Once you have done this, you can import all your GitHub repositories to GitLab. To do this, you first need to create a new project. Click on the drop-down arrow next to the plus sign in the top-right corner and select “New project”. This will open the following window:</p>
<p><img alt="" src="https://i0.wp.com/shiring.github.io/tutorials/2017/09/04/Bildschirmfoto1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Here, choose “Import project from GitHub” and choose the repositories you want to import.</p>
<p>If you go into one of your repositories, GitLab will show you a message at the top of the site that tells you that you need to add an SSH key. The SSH key is used for secure communication between the GitLab server and your computer when you want to share information, like push/pull commits.</p>
<p><img alt="" src="https://i2.wp.com/shiring.github.io/tutorials/2017/09/04/Bildschirmfoto2.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>If you already work with GitHub on your computer, you will have an SSH key set up and you can <a rel="nofollow" href="https://gitlab.com/profile/keys" target="_blank">copy your public SSH key to GitLab</a>. Follow the instructions <a rel="nofollow" href="https://gitlab.com/help/ssh/README" target="_blank">here</a>.</p>
<p>Here is how you do it on a Mac:</p>
<ol>
<li>Look for your public key and copy it to the clipboard</li>
</ol>
<p></p>
<div>
<pre><code>cat ~/.ssh/id_rsa.pub
pbcopy &lt; ~/.ssh/id_rsa.pub
</code></pre>
</div>
<p>Then paste it into the respective field <a rel="nofollow" href="https://gitlab.com/profile/keys" target="_blank">here</a>.</p>
<p>The next step is to change the remote URL for pushing/pulling your project from RStudio. In your Git window (tab next to “Environment” and “History” for me), click on Settings and “Shell”.</p>
<p><img alt="" src="https://i2.wp.com/shiring.github.io/tutorials/2017/09/04/Bildschirmfoto3.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Then write in the shell window that opened:</p>
<div>
<pre><code>git remote set-url origin git@</code></pre></div>