Skip to content

Set up Git

Time for you to install Git and get acquainted with GitLab. Tobias guides you through the steps. The video is a few years old, so follow the steps below for what to actually do.

11:53

Download and install the latest version of Git from git-scm.com/downloads. More information is available in Getting started - installing Git.

Open the terminal window that belongs to your platform.

Search for and open Git Bash, which is installed together with Git. All instructions in this guide assume Bash.

Searching for Git Bash in the Windows start menu

New to Bash? Have a look at Basics of Bash for beginners.

git --version

Depending on your Git version, the output should look something like this:

git version 2.55.0

List your current Git settings:

git config --list

If the output shows a list of settings, everything works as expected and you can move on.

Add the name you want associated with your changes:

git config --global user.name 'Ellen Nu'

Read more about this in Setting your username in Git.

You should get your name as output when you run:

git config --global user.name

It’s important that you use your student email.

git config --global user.email 'en999zz@student.lnu.se'

Read more about this in Setting your email in Git. Already had Git installed, but not configured with your student email? See Multiple Git user configs for help with handling several configurations on the same computer.

You should get your email address as output when you run:

git config --global user.email

SSH (Secure Shell) is an encrypted network protocol for secure data communication over an unsecured network. When working with Git and GitLab, SSH gives you several advantages:

  • Secure communication - data sent between your computer and the GitLab server is encrypted, so code and sensitive information can’t easily be intercepted.
  • Password-free authentication - once SSH keys are set up, you don’t need to enter a username and password every time you push or pull.
  • Identity verification - SSH keys come in pairs: a private key that stays on your computer and a public key you upload to GitLab. Only whoever holds the private key can authenticate.
  • Smoother workflow - no need to enter credentials every time you interact with a repository.

You will likely create more SSH keys later on, one per service (for example, virtual private servers in the university’s cloud). So give the key a service-specific name instead of the Git tools’ default name, so that it isn’t overwritten or mixed up with other keys later.

  1. Generate an SSH key pair with a name that says what it’s used for:

    ssh-keygen -t ed25519 -C "en999zz@student.lnu.se" -f ~/.ssh/id_ed25519_gitlab_lnu -N ""

    The command finishes right away with a summary that looks something like this:

    Generating public/private ed25519 key pair.
    Your identification has been saved in ~/.ssh/id_ed25519_gitlab_lnu
    Your public key has been saved in ~/.ssh/id_ed25519_gitlab_lnu.pub
    The key fingerprint is:
    SHA256:IO1ESdUxg9Q6p6ggEcc10jbJr1TW9GDWhNu01iTcrSs en999zz@student.lnu.se
    The key's randomart image is:
    +--[ED25519 256]--+
    | ..+ooo*BO=o . |
    |. o.*++o+oBoo . |
    | o ..=+ =.= . |
    |. .+..+ = o |
    | . . ...S= . |
    |. . . . . E . |
    | . . . . |
    | . |
    | |
    +----[SHA256]-----+

    This creates a public key (id_ed25519_gitlab_lnu.pub) and a private key (id_ed25519_gitlab_lnu) in your ~/.ssh directory.

    Your ~/.ssh directory now contains roughly the following:

    • Directory.ssh/
      • id_ed25519_gitlab_lnu
      • id_ed25519_gitlab_lnu.pub
  2. Open id_ed25519_gitlab_lnu.pub in a text editor and copy its entire contents.

  3. Log in to your GitLab account and go to SSH Keys in your profile settings. Click Add new key, paste the copied public key into the Key field and replace the prefilled value in Title with id_ed25519_gitlab_lnu, so you can recognize it among several keys later. Leave Usage type and Expiration date as they are and save.

    GitLab's form for adding an SSH key, with the Key and Title fields and the Add key button marked with the numbers 1 to 3
    The screenshot is taken in GitLab Enterprise Edition v19.2.4-ee. The interface may look different in later versions.
  4. Since the key no longer has one of SSH’s default names, you need to point it out explicitly for gitlab.lnu.se. Add the following to ~/.ssh/config (create the file if it doesn’t exist):

    Host gitlab.lnu.se
    HostName gitlab.lnu.se
    User git
    IdentityFile ~/.ssh/id_ed25519_gitlab_lnu
  5. Test the connection by running ssh -T git@gitlab.lnu.se in the terminal. If it works, you get a welcome message from GitLab.

Your ~/.ssh directory now contains roughly the following:

  • Directory.ssh/
    • id_ed25519_gitlab_lnu
    • id_ed25519_gitlab_lnu.pub
    • config
    • known_hosts

Running into problems with the SSH keys? See Troubleshooting SSH, or read GitLab’s official documentation.

Git and GitLab are now ready to use! If you are new to Git and/or Bash, the following resources may help:

CCBY