# Git and GitLab

## Table of Contents

- Installing Git
  - Linux (debian, ubuntu)
  - Mac OSX and Windows
- Authenticating on GitLab
  - Option 1: HTTPS
    - Configuring your GitLab password
    - Making sure git remembers your password
  - Option 2: SSH
    - Installing SSH
    - Setting up SSH on GitLab

So far, you only used git via the web interface from the GitLab we deployed for the MOOC.

https://app-learninglab.inria.fr/gitlab/

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 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):

    apt-get update ; apt-get install git

### Mac OSX and Windows

- Download and install Git from the Git website.
- Optional Git clients (should not be needed if you work within Rstudio):
  - SourceTree

  - GitHub Desktop

    > Apparently, this works with GitLab and https.

## 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 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.

    git clone https://app-learninglab.inria.fr/gitlab/3211ac4f2fb71deaeff9252764c368e7/mooc-rr

This can be quite painful, which is why you can also provide them once and for all when cloning, as follows:

    git clone https://3211ac4f2fb71deaeff9252764c368e7:tototutu@app-learninglab.inria.fr/gitlab/3211ac4f2fb71deaeff9252764c368e7/mooc-rr

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 these instructions:

    git config --global credential.helper cache                  # remember my password
    git config --global credential.helper "cache --timeout=3600" # for one hour at most

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):

      apt-get update ; apt-get install openssh-client

- Mac OSX

  You do not have anything to do as it is installed by default.

- Windows

  You should install the Putty client. Once it is installed, look for the section on generating an SSH key.

#### Setting up SSH on GitLab

Here are 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: