Chapter 3: Programming Courseworks

git setup

face Josiah Wang Tom Crossland

In order to use git fully, we’ll need to do a little bit of setup. This only needs to be done once on the DoC computers.

First, we need to set up something called an SSH key. This key will be in two parts: public and private. You can think of an SSH key like a password (if a slightly more complicated one).

Setting up an SSH key and adding the public key to your GitLab account will allow you to easily make changes to your git repo and upload them to GitLab.

To create an SSH key, run the following (you don’t need to replace the $USER):

ssh-keygen -t rsa -C "$USER@imperial.ac.uk"

Accept the default options – in particular, don’t change the location or name of the key (which should be ~/.ssh/id_rsa. Enter a passphrase when prompted.

This will create a private key at ~/.ssh/id_rsa and a public key at ~/.ssh/id_rsa.pub.

Do not share your private key with anyone! It is the “password” part of your SSH key.

Now you want to copy the contents of your public key to the clipboard, and head over to GitLab.

In GitLab, find your “User Settings”, and go to the tab marked “SSH Keys”. Click the button marked “Add new key”, and then paste the contents of your public key file into the “Key” field. Give it a title, leave “Usage type” with its default value, and choose an expiration date that will allow you to keep using this key all year!

Press “Add key”, and success! You now have an SSH key.

Finally, we need to add some configuration to git on your DoC machine.

In your terminal, write the following lines, replacing the name and email with your own (use your Imperial email):

git config --global user.name "Julius Caesar"
git config --global user.email "julius.caesar@imperial.ac.uk"

This will let git know who is making the changes to your repos (and who to blame if things go wrong!).

A more thorough guide to using git with the DoC system is available.