Before you are able to clone a repo down from GitLab you’ll need to first generate a pair of SSH keys – a private key and a public key. These keys are used to authenticate your session in GitLab. The private key should never be shared and never be part of your repo. The public key is what will be shared with GitLab.

Create the key

On your mac start the terminal and type the following command:

$ ssh-keygen -t rsa -C "$your_email@somewhere.com"

You will be asked where to place the resulting key file. You should follow the example path that is presented to you since that path is where Git (actually, SSH on behalf of Git) will look for the key to see if it matches the public key that you will paste into your GitLab project (that’s a very simple and somewhat inaccurate description of what really happens but its close enough for our purposes). To accept the default path just hit Enter on your keyboard.

You will be asked for a password – you can leave it blank or supply a password at your discretion though the best practice is to enter a password especially if multiple people have access to your dev machine. Otherwise if your machine is secure you can leave out the password and thus enjoy transactions that don’t prompt for passwords.

View the Public Key

Enter this command into the terminal to view the public key you’ve just created:

$ cat ~/.ssh/id_rsa.pub

Your key will appear – copy the key text starting from ssh-rsa all the way to your username/host.

Add the Key to Your GitLab Profile

Log into GitLab and locate your profile settings (which is the cog wheel in the upper right row of icons). Then click “Add SSH Key”. Here you will be presented with a text area within which you will paste the public key you generated. Paste it in, add a description, then click “Create”.

Clone the Repo

You’re ready to go, again in GitLab, locate the desired project and note the project path. Copy it.

Next, in terminal, clone your repo by typing:

$ git clone paste_your_repo_path_here desired_folder_here

If you created the key with a password you will be prompted at this point to enter it.

The repo will be cloned to your machine.