git and gitlab
To grade your labs, we will use the gitlab hosted by the binet association. gitlab is an online developer platform used to store your code.
Creating an account
In theory, you should already have an account. To check that it is the case, try to log in on https://gitlab.binets.fr. If that’s not the case, you need to activate your account by clicking on “ma première connexion” on the Sigma server (https://sigma.binets.fr/app/login).
Creating a repository
Once you have your account, you have to create a project named cse201 by clicking on the New project button. For the project group, pick your own name, and for the project “name”, use “cse201”. Let the visibility as private, and unselect "Initialize repository with README". Finally, click on "Create repository". You should now see your beautiful project. Since the project is empty, you should see some instructions explaining how to start.
What you have created on gitlab is named a "repository". A repository is like a directory where you store your source files. It's not so far from dropbox, but tailored for development. gitlab manages the repository with the git tool. git is a "distributed version control system". It means that git keeps an history of the files stored in the repository. It's very useful if you make mistakes when you modify your code, and want to retrieve an older version of a file.
Adding your professors as a friend
Now, you have to add your professors in your project through the web interface. For that, click on "Manage", then "Members", and finally "Invite member". Type "gael.thomas" and selects the user. Modify the role to Developper, otherwise, we will not see your code. Finally, click on invite. Do the same with the user "julien.tierny".
Adding a ssh key to gitlab
For the moment, your source files are stored in the servers of gitlab. To work with them, you have to copy them locally on your machine. For that, you have first to create what we name a ssh keypair, which is used as an authentication token to load and store the files in your repository. Technically, a ssh keypair contains a public and a private key. You give the public key to someone (in our case gitlab), and you use the private key to generate an authentication token. Since only the owner of the private key can create a token that matches the public key, anyone can verify that you are actually the owner of a public key, which authenticates you.
To create this keypair, you have to use the ssh-keygen tool. Then you have to display the public key and to record it in gitlab. For that, you have to launch a terminal (by launching the terminal application for the Mac users, or by starting WSL for the Windows user). In the terminal, type the following commands:
At this step, you should see your public key in the terminal. Through the gitlab web interface, click on your profile, then preferences, then SSH Keys and then add new key. In the Key field, copy paste copy-paste the public key that you see in the terminal, and then click on "Add key".
Configuring you user name and password
With git, when you write code, other developers must be able to identify you. To do this, they need your name and an email address to contact you in case of a problem. For this reason, you need to configure your git developer name and email on your local machine by copying and pasting into a terminal the two lines starting with git config --global that are displayed on the gitlab web page.
Cloning and importing lab1
Now, you will clone your repository onto your machine. To do that, you have to execute the commands provided in the "Push an existing folder" section displayed on the gitlab web page. In detail, you have to go into your local cse201 directory with the cd command (the cse201 directory is the one where you have lab1/sudoku.c), and then copy-paste the set of commands that start with git clone git@....
Among the lines that you copy-pasted, two are of interest for the rest of the course: the line git add . and the line that starts with git commit -a -m.
The add command of git adds a local file to what is called the local "index". The "index" is a sort of waiting room in your local copy of the repository where you accumulate the files that will be sent to the remote repository. Here, with git add ., you've added all the files of your cse201 directory to the index, which means that all the files of the first lab are now in the index.
Then, to send your changes to gitlab, you have to proceed in two steps. First, you have to create what we call a local commit. A commit is a snapshot of your code. In detail, a commit includes changes to all files that were previously added to git with git add. In general, to commit your code, you have to type git commit -a -m "My commit message". Here:
- The "-a" flag means that all the files that were added in a previous commit have to be committed. In this case, it's useless since it's your first import. However, for the next commits, it will be very useful to use this flag.
- The "-m" flag means that the next parameter is the commit message. A commit message is very useful to keep track of the changes you made in each commit.
During the rest of the course, once you have committed your changes locally, you have to deploy them to the gitlab server. For that, you just have to type git push, which pushes your local commit to the server.
To summarize, during the course, after having written your code, you just have to type these commands to submit your code:
At this step, if you refresh the gitlab web page, you should see that your first lab is in the repository.