This page explains Git and Gitlab. Parts of this description are also shown in the first practical. Alternatively, you can also watch a tutorial (in German), created by a lecturer teaching this course previously.

Overview

Git is a version control program that was programmed to manage the development of the Linux kernel. Today, however, so many other software projects already rely on Git that it is hard to imagine software development without it. Who works with Git has access not only to the current state of his project folder but also to previous versions. So if a bug appears in a new version, we can revert to an older bug-free version with the help of Git. Comparing different versions also allows us to more quickly identify the source of a bug. In addition to working in a local project folder, Git also supports saving the project on online platforms such as Gitlab.

SSH Key

At the beginning, we need to make sure that our PC can communicate with the Gitlab server. This communication is encrypted and we use the SSH protocol. For this we need to create a private key (for us) and a public key (for Gitlab) once. After that, it is possible to interact with Gitlab without having to enter a password every time, as it would be necessary with the HTTPS protocol.

We open the FileSystem in the VM and select the folder student in the left bar. With CTRL+H we can now show all hidden items. (Hidden folders and files start with a dot in Linux.) We now open the folder .ssh (note the dot!). If it does not exist, we have to create it first and open it afterwards.

In the .ssh folder we now open the terminal by right-clicking in the folder and selecting Open Terminal here. Now we can generate our required key pair (i.e. the private and the public key) with the following command:

ssh-keygen -o -t rsa -b 4096

We are now asked for a filename and a password. In both cases we can simply confirm with Enter, this way the default filename is used and the private key is not encrypted itself.

Now the .ssh folder should no longer be empty, but contains the two generated keys. We now copy the contents of the file with the extension .pub (the public key) to the clipboard. This can be done, for example, with the command

cat id_rsa.pub

This will display the file contents and we can select and copy them (right click and copy or CTRL+SHIFT+C).

Now we log in to Gitlab (if not already logged in), click on the profile in the upper right corner and select Edit profile. Then we select SSH keys in the left panel and paste the public key from the clipboard into the key field. With Add key we add our key.

Clone a Repository

We open the repository in Gitlab, then a blue button with the inscription Clone should be visible. We now copy the address that is stored in Clone with SSH. Next, we open the folder in the VM where we would like to save it (e.g. in the shared folder). In this folder we open the terminal by right clicking in the folder and selecting Open in Terminal here. Then we enter the command

git clone <address>

where <address> is to be replaced by the previously copied SSH address. (Paste into the terminal is possible by right-clicking Paste or CTRL+SHIFT+V).

When cloning for the first time (or using the SSH key) we need to confirm that we want to connect, just enter yes and confirm with Enter. With this we have successfully cloned our repository to our PC and it should be in the opened folder.

Upload Changes to Gitlab

After having completed some work in the repository, we may want to upload the changes to Gitlab. For the following chapter, we assume that a file called a0.c was created. To upload we only need three commands: git add, git commit and git push. However, we start with a different command