Version control with Git: Setup

Files

There are no files required for this lesson. You will create all the files needed.

GitHub account

You will need a GitHub account to follow this course. Sign up if you don’t already have an account.

Software

Git

Git is free and open-source software, available for all operating systems.

Installation on a managed desktop PC

Git for Windows is available for self-installation from the Software Centre (search for ‘git’).

Installation on personal and unmanaged machines

See here for installation instructions for the major operating systems.

SSH keys

Please set up SSH keys for authentication with GitHub. This is a two step process:

  1. Create SSH keys on your laptop
  2. Add the public key to GitHub

SSH is an encrypted network protocol which we will use to securely access our remote repository. In order to use it, we need to set up a pair of SSH keys, which are used together to validate access. There’s a private key, and a public key - GitHub needs to know the public key, but the private key stays only on your computer. A useful analogy is to think of the public key as a padlock, and the private key as the only key to the padlock.

Create ssh keys

Let’s first check whether we already have ssh keys set up:

$ ls ~/.ssh

If you already have ssh keys set up, your output will look something like this:

id_ed25519  id_ed25519.pub

and you can skip to the next section (Add public ssh key to GitHub).

If you still need to set up ssh keys, you’ll get a message like this:

ls: cannot access '/home/yourusername/.ssh': No such file or directory

To set up the key pair, we use the following command

$ ssh-keygen -t ed25519 -C "your_email@example.com"

You might get an error from this if your system doesn’t support the ed25519 algorithm, in which case you can try $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/you/.ssh/id_ed25519):

Accept the default option using Enter.

Created directory  '/home/you/.ssh'.
Enter passphrase (empty for no passphrase):

Enter a password (you’ll be prompted to enter it twice)

Your identification has been saved in /home/you/.ssh/id_ed25519
Your public key has been saved in /home/you/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:SMSPIStNyA00KPxuYu94KpZgRAYjgt9g4BA4kFy3g1o your_email@example.com
The key's randomart image is:
+--[ED25519 256]--+
|^B== o.          |
|%*=.*.+          |
|+=.E =.+         |
| .=.+.o..        |
|....  . S        |
|.+ o             |
|+ =              |
|.o.o             |
|oo+.             |
+----[SHA256]-----+

Now that we have generated the SSH keys, we will find the SSH files when we check.

$ ls ~/.ssh
id_ed25519  id_ed25519.pub

We can view the public key using

$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI your_email@example.com

Now you should copy the output from this command ready for the final step.

Add public ssh key to GitHub

The final step is to add the public key to our GitHub accounts.

You can verify your SSH set up was successful like this:

$ ssh -T git@github.com
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.

Set the default GitHub branch name to ‘master’

As we will see in episode 2, the default branch name in a git repo is master.

In 2021 GitHub and many other remote repo providers changed their settings so that new repositories will use main instead of master. As ever there are arguments for and against this change. We can however choose the default branch name in our GitHub settings, so let’s set it to master to be consistent with the git software itself.

On GitHub, click on your profile photo at the top right of the page. Then go to Settings -> Repositories -> Repository default branch.

Change ‘main’ to ‘master’ and click ‘update’.

Please get in touch before the course starts if you run into any problems with set up!