Skip to main content

Install and Configure Git

Ubuntu

Install Git

  1. Update the package index:

    sudo apt update
  2. Install Git:

    sudo apt install git
  3. Verify the installation:

    git --version

Configure Git

  1. Set your username:

    git config --global user.name "Your Name"
  2. Set your email:

    git config --global user.email "your.email@example.com"
  3. View the configuration:

    git config --list
  4. Optional: Set the default text editor:

    git config --global core.editor vim
  5. Optional: Set an alias:

    git config --global alias.gs status

Rocky Linux

Install Git

  1. Update the package index:

    sudo dnf update
  2. Install Git:

    sudo dnf install git
  3. Verify the installation:

    git --version

Configure Git

  1. Set your username:

    git config --global user.name "Your Name"
  2. Set your email:

    git config --global user.email "your.email@example.com"
  3. View the configuration:

    git config --list
  4. Optional: Set the default text editor:

    git config --global core.editor vim
  5. Optional: Set an alias:

    git config --global alias.gs status

Configure SSH Keys

Generate an SSH Key

Generate an SSH key:

ssh-keygen

Press Enter through all the prompts, and the key pair will be generated. The key pair is typically stored in ~/.ssh.

Copy the Public Key and Add It to Your Git Service

  1. Copy the public key content:

    cat ~/.ssh/id_rsa.pub
  2. Add the public key to your Git service (e.g., GitHub, GitLab, etc.) in the SSH key settings.