# -*- mode: org -*- #+TITLE: Git and GitLab #+AUTHOR: Arnaud Legrand #+DATE: June, 2018 #+STARTUP: overview indent #+OPTIONS: num:nil toc:t #+PROPERTY: header-args :eval never-export So far, you only used git via the web interface from the GitLab we deployed for the MOOC. #+BEGIN_CENTER https://app-learninglab.inria.fr/gitlab/ #+END_CENTER If you access this link from the FUN platform, you do not have to authenticate and you can readily read and modify all your files. This is very convenient but in most cases, you will want to have your own local copy of the repository and you will have to synchronize your local copy with the remote GitLab one. To propagate your modifications, you will obviously have to authenticate yourself on GitLab. How to do this is illustrated in a [[https://www.fun-mooc.fr/courses/course-v1:inria+41016+session01bis/courseware/66bc811404b8481da5f794de54681c5e/f6580ad8e997400faeffe9af4fd37063/2][video tutorial]] (in French). This document describes the software you need to have installed on your machine and how to handle authentication. Please read these instructions carefully. * Installing Git ** Linux (debian, ubuntu) We provide here only instructions for debian-based distributions. Feel free to contribute to this document to provide up-to-date information for other distributions (e.g., redhat, fedora). Run (as root): #+begin_src sh :results output :exports both apt-get update ; apt-get install git #+end_src ** Mac OSX and Windows - Download and install Git from the [[https://git-scm.com/downloads][Git website]]. - Optional Git clients (should not be needed if you work within Rstudio): - [[https://www.sourcetreeapp.com/][SourceTree]] - [[https://desktop.github.com/][GitHub Desktop]] #+BEGIN_QUOTE [[https://github.com/desktop/desktop/issues/852][Apparently]], this works with GitLab and https. #+END_QUOTE * Authenticating on GitLab There are two ways of authenticating and synchronizing your local repository with GitLab: through HTTPS or through SSH. The first one does not require any particular software installation on your machine so this is what I recommend for this MOOC. Yet, I also describe the second one as it is the one I prefer (once it is well configured, it never asks me for any password anymore and I don't have to remember anything). ** Option 1: HTTPS *** Configuring your GitLab password In this [[https://www.fun-mooc.fr/courses/course-v1:inria+41016+session01bis/courseware/66bc811404b8481da5f794de54681c5e/f6580ad8e997400faeffe9af4fd37063/2][video tutorial]] (in French), I explain how to change your password on our GitLab. *** Making sure git remembers your password My GitLab id is =3211ac4f2fb71deaeff9252764c368e7=. Say I've configured my password to be =tototutu= (what a weak password...) and I want to clone my =mooc-rr= repository. If you clone your repos by simply pasting the GitLab url (e.g., with the following command line) you will be prompted for your login and your password every time you want to propagate your local modifications. #+begin_src shell :results output :exports both git clone https://app-learninglab.inria.fr/gitlab/3211ac4f2fb71deaeff9252764c368e7/mooc-rr #+end_src This can be quite painful, which is why you can also provide them once and for all when cloning, as follows: #+begin_src shell :results output :exports both git clone https://3211ac4f2fb71deaeff9252764c368e7:tototutu@app-learninglab.inria.fr/gitlab/3211ac4f2fb71deaeff9252764c368e7/mooc-rr #+end_src This is very convenient but there is one drawback to understand. This means your password is stored, unencrypted on your hard drive. If anyone ever gets an access to your machine, he will gain access rights to all your repos, which can be problematic. This is why the really good way to do this is to follow [[https://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-on-github][these instructions]]: #+begin_src shell :results output :exports both git config --global credential.helper cache # remember my password git config --global credential.helper "cache --timeout=3600" # for one hour at most #+end_src With this setup, you will be prompted for your password but it will be cached in memory and they will not be asked again before an hour. ** Option 2: SSH My preferred (although more technical) solution is to install SSH, to create a pair or private/public keys, and to upload your SSH public key on GitLab. This section provides with information on how to do this. *** Installing SSH **** Linux (debian, ubuntu) We provide here only instructions for debian-based distributions. Feel free to contribute to this document to provide up-to-date information for other distributions (e.g., redhat, fedora). Run (as root): #+begin_src sh :results output :exports both apt-get update ; apt-get install openssh-client #+end_src **** Mac OSX You do not have anything to do as it is installed by default. **** Windows You should install the [[https://www.ssh.com/ssh/putty/windows/][Putty]] client. Once it is installed, look for the section on [[https://www.ssh.com/ssh/putty/windows/puttygen][generating an SSH key]]. *** Setting up SSH on GitLab Here are [[https://docs.gitlab.com/ee/ssh/][all the official explanations on how to set up your SSH key on GitLab]]. Alternatively, you may also want to have a look at this video: #+BEGIN_EXPORT html #+END_EXPORT