MRC/Tutorials/Git
Creating a software solution together means sharing a project, which in our case means sharing code. We will be using git for this. Git is "a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency":
- version control means that the files and changes you make to them are 'tracked' over time, i.e., their 'history' is stored. You can always go back to previous versions, show the differences between a certain point in time and now, and much more.
- distributed means that you don't necessarily need a central server to store your changes. Every team member has the full history available, and can always save his or her changes or go back to previous versions, even if he or she is offline. However, note that it is possible to use a central server that every team member writes his or her changes to, and receives the changes others made from. In this project, we will be using such a central server.
Clone a project
The examples you worked on up until now are stored on your own computer, which is fine if you are the only person working on your project. However when working with a team you need every member to have access to the most recent version of the code base. Well, sharing is easy in git! Your teammates can get a local copy of the repository. This is called 'cloning', and works as follows.
The MRC team has already initialized a git repository for you which includes a small example. To share the repository with your group we will use GitLab. GitLab is open source software to collaborate on code. The TU/e has its own gitlab server which we will make use of. Now:
- Browse to gitlab.tue.nl and click the TU/e login button - Take the steps you usually take to login to your TU/e account - E-mail your username (that starts with @) to Peter van Dooren (only one group member has to send their username) - Once we have added you to your group's project, you will receive an e-mail with the link to your repository - You can then add your colleagues to your project and start collaborating!
Before you can clone the repository we will have to tell gitlab it can trust your computer. For this we use a process called ssh. In a terminal type
ssh-keygen
Don't enter anything when given prompts. Simply press enter two or three times. We don't really need a passphrase for this ssh key and we can use the default location. After doing this type
cat ~/.ssh/id_rsa.pub
This will print your public ssh key to the terminal. Next, on gitlab select edit profile on your own profile. In the tab SSH Keys select `Add new key`. In the key field copy paste your public ssh key. (remember that in a terminal copy is done via ctrl+shift+C). Give your key a descriptive name such as "MRC-virtual-ubuntu" and add the key.
SSH is communication protocol. The keys we use are a way for computers to verify eachothers identity. When you communicate with gitlab on your virtualbox the computer will automatically authenticate itself with this key. Think of it like a password for computers.
Once you added your ssh key to your account you can clone your groups repository using the following command (fill in the your group name for <GROUP_NAME>, or copy the whole link from the GitLab page of your group):
cd ~/mrc
git clone https://gitlab.tue.nl/mobile-robot-control/2024/<GROUP_NAME>.git shared_project
This will create a directory called 'shared_project' in which you will find the files that someone else made. Now, this is your local copy of the repository to which you can make changes. We will learn here how we can save those changes and safely store these changes to the central server.
In git terminology, we commit changes to our local repository and then push these changes to the remote. So, let's do this!