How to Install and Set Up Git on Ubuntu 22.04: A Step-by-Step Guide

Setting up Git on Ubuntu 22.04 is a straightforward process. Here’s a step-by-step guide:

Step 1: Update the Package Index

Before installing Git, ensure your system is up-to-date:

sudo apt update && sudo apt upgrade -y

Step 2: Install Git

Run the following command to install Git:

sudo apt install git -y

Step 3: Verify the Installation

Check the installed version of Git to confirm the installation:

git --version

Step 4: Configure Git

You need to configure Git with your user information (name and email) for commits. Replace Your Name and your.email@example.com with your details:

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

Step 5: Verify Git Configuration

To check your configuration:

git config --list

Step 6: Set Up SSH Key (Optional but Recommended)

If you plan to use SSH with GitHub, GitLab, or another Git server:

  1. Generate an SSH Key:
    ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

    Press Enter to accept the default file location and set a passphrase (optional).

  2. Add the SSH Key to the SSH Agent:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_rsa
  3. Copy the SSH Key to Your Clipboard:
    cat ~/.ssh/id_rsa.pub

    Copy the output and add it to your Git server account under SSH keys.

Step 7: Test SSH Connection (if applicable)

To ensure the SSH key works, test the connection:

ssh -T git@github.com

Replace github.com with your Git server’s domain.

Step 8: Start Using Git

You can now clone repositories, commit changes, and push code using Git. For example:

git clone https://github.com/username/repository.git

Let me know if you encounter any issues!

No episodes found.Posted in git, UbuntuTagged , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *