DevCloudLab More courses at DevCloudLab.com →
FLUX CD · SECTION 2 · LECTURE 1

DevCloudLab

Installing and configuring Git

Section 2, Lecture 1, from the Flux CD course by DevCloudLab.


What you’ll learn

Overview

This lecture covers installing Git on Windows, macOS, and Linux, then configuring Git for local use and setting up SSH authentication for remote repositories.

Installation Commands

Windows

  1. Download Git for Windows from https://gitforwindows.org
  2. Run the installer and accept the defaults
  3. Open Git Bash, the terminal that Git for Windows installs with Git built in. Run your Git commands there.
  4. Verify installation:
    git --version
    

macOS

  1. Using Homebrew (if installed):
    brew install git
    
  2. Or download from https://git-scm.com/download/mac and run the installer
  3. Verify installation:
    git --version
    

Linux (Ubuntu/Debian)

  1. Update your package manager:
    sudo apt update
    

    Fetch the latest list of available packages.

  2. Install Git:
    sudo apt install git -y
    

    The -y flag skips the confirmation prompt.

  3. Verify installation:
    git --version
    

    Display the installed Git version number.

Configuring Git

Set Your User Information

Git needs to know your name and email for every commit:

git config --global user.name "Your Name"

Sets your name globally on this machine.

git config --global user.email "your.email@example.com"

Sets your email globally on this machine.

Verify Your Configuration

git config --global user.name

Display the configured user name.

git config --global user.email

Display the configured email address.

Set Your Default Text Editor

Git uses a text editor for commit messages and merge conflict resolution. By default it uses your system’s default editor, which is often Vim or Nano. To choose a different one, set it explicitly:

Vim:

git config --global core.editor "vim"

Visual Studio Code:

git config --global core.editor "code"

Only works if you have the code command in your PATH.

Sublime Text:

git config --global core.editor "subl"

Only works if you have the subl command in your PATH.

Nano (simple):

git config --global core.editor "nano"

Verify Editor Configuration

git config --global core.editor

Display the configured editor.

SSH Authentication Setup

SSH lets you authenticate to Git repositories without storing passwords in plaintext.

Step 1: Generate an SSH Key Pair

ssh-keygen -t ed25519 -C "your.email@example.com"

Generate a new SSH key using Ed25519 (modern and secure). The -C flag adds a comment (email) to label the key.

Step 2: Start the SSH Agent

eval "$(ssh-agent -s)"

Start the SSH agent, a background process that holds decrypted keys in memory.

Step 3: Add Your Key to the Agent

ssh-add ~/.ssh/id_ed25519

Register your private key with the agent so it can be used for authentication.

Step 4: Display Your Public Key

cat ~/.ssh/id_ed25519.pub

Print the contents of your public key. This is the value you will upload to GitLab. It should look like:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIxxx... your.email@example.com

Adding Your SSH Key to GitLab

  1. Visit https://gitlab.com and log in
  2. Click your avatar in the left sidebar
  3. Select Edit profile
  4. Click SSH Keys, then Add new key
  5. Paste your public key (from cat ~/.ssh/id_ed25519.pub) into the Key box
  6. Click Add key

Since this video was recorded: GitLab has moved this page. The video clicks the profile icon in the top right corner, then Preferences, then SSH Keys. Today the path is the avatar in the left sidebar, then Edit profile, then SSH Keys, then Add new key.

Test Your SSH Connection

Not shown in the video: an optional check that your key works.

ssh -T git@gitlab.com

Attempt to connect to GitLab via SSH.

The first time you connect, SSH has no record of gitlab.com and asks you to confirm its host key:

The authenticity of host 'gitlab.com (...)' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type yes and press Enter. Pressing Enter on its own just re-asks. If everything is set up correctly, a welcome message from GitLab follows.

Reference: Global Configuration Files

Not shown in the video: where the settings above are stored.

Your Git configuration is stored in a plain text file in your home directory:

Location: ~/.gitconfig

Example content:

[user]
    name = Your Name
    email = your.email@example.com
[core]
    editor = vim

You can also view all your global configuration with:

git config --global -l

List all global Git settings.

Further Reading

Troubleshooting

Issue: git: command not found

Solution: Git is not installed or not in your PATH. Reinstall Git or add it to your PATH environment variable.

Issue: ssh-add fails with “Could not open a connection to your authentication agent”

Solution: The SSH agent is not running. Start it with eval "$(ssh-agent -s)" first.

Issue: SSH connection to GitLab fails

Solution: Verify your public key was uploaded to GitLab. Check that there are no extra spaces or line breaks in the pasted key.

Issue: Permission denied when trying to use SSH key

Solution: Ensure your private key file has the correct permissions. Run chmod 600 ~/.ssh/id_ed25519.


DevCloudLab

Built by DevCloudLab
Hands-on cloud-native courses: Kubernetes, GitOps, CI/CD and the cloud.
Visit DevCloudLab.com →