Git is a distributed version control system that tracks changes to code, files, and project directories across any platform including Ubuntu.
Ubuntu 24.04 may include Git by default, but you can also install a specific version from the apt repositories or build one from source.
Quick Answer
Run sudo apt install git to install Git on Ubuntu 24.04. Verify with git –version and then set your identity with git config –global user.name and user.email.
Method 1: Install Git on Ubuntu 24.04 Using APT
APT is the simplest way to install Git on Ubuntu 24.04. It pulls the latest stable version from Ubuntu’s official repositories without any manual compilation.
Step 1: Check if Git Is Already Installed
Run the version check command first. Ubuntu 24.04 ships with Git pre-installed, so this step may confirm that no additional installation is needed.
git --version

Step 2: Install Git via APT
If Git is not present or you want to update to the latest apt version, run the install command below. The package name is simply git in the Ubuntu repositories.
sudo apt install git
Method 2: Install a Specific Git Version from Source
Building from source lets you pick any Git version. Download the tarball from the kernel.org mirrors, compile it, and install the binaries to /usr/local.
Step 1: Install Build Dependencies
Install the required compiler tools and libraries before building Git. These packages provide SSL support, compression, and other essentials needed at compile time.
sudo apt install build-essential libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc -y

Step 2: Download the Git Source Tarball
Create a temporary directory, navigate into it, and download the Git source archive. Replace 2.38.0 in the URL with the version number you want to install.
mkdir tmp
cd /tmp
curl -L https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.38.0.tar.gz -o git.tar.gz

Step 3: Extract and Compile Git
Extract the tarball, navigate into the resulting directory, and run make to compile the Git source before running the install command in the next step.
tar -zxf git.tar.gz

cd git-*
make prefix=/usr/local all

Step 4: Install and Verify Git
Run make install with sudo to copy the compiled binaries to /usr/local, then reload the shell so it picks up the newly installed Git version automatically.
sudo make prefix=/usr/local install

exec bash
git --version

Method 3: Configure Git on Ubuntu 24.04
After installing Git, set your global identity so every commit includes your name and email. These values must match your GitHub or GitLab account credentials.
Step 1: Set Your Username and Email
Run the two git config commands below to set your global username and email, then run git config –list to confirm the values were saved correctly.
git config --global user.name "Your Username"
git config --global user.email "Your Email Address"
git config --list

Step 2: Edit the .gitconfig File Directly
You can also open the ~/.gitconfig file in any text editor and enter your name and email under the [user] section, which achieves the same result as git config.
nano ~/.gitconfig

Common Git Commands
With Git configured, you can run version control commands directly in the terminal. Below are the most commonly used Git commands and what each one does.
git init — Initializes a new local repository in the current directory, creating the hidden .git folder that tracks your project’s full history.
git clone [url] — Copies an existing remote repository to your local machine, including its complete commit history and all branches.
git status — Shows which files have changed, which are staged for commit, and which are untracked in your current working directory.
git add [file] — Moves a specific file or all changed files to the staging area, marking them to be included in the next commit you run.
git commit -m ‘message’ — Records all staged changes as a permanent snapshot in the repository history with a short descriptive commit message.