Tutorials  /  Ubuntu

Install and Use Git on Ubuntu 24.04 – Complete Guide

Ccentron Redaktion · August 2025 ·9 min read ·Ubuntu, Tutorial

Git is a widely-used open-source distributed version control system designed to manage and record project modifications, particularly throughout software development workflows. It empowers multiple developers to simultaneously contribute to the same codebase while preserving a full history of changes. Through platforms such as GitHub, GitLab, and Bitbucket, Git facilitates seamless collaboration and synchronization.

This tutorial walks you through the process of installing the latest Git release and setting it up for both local and remote repository use within your development environment on Ubuntu 24.04.

Prerequisites

Ensure the following before proceeding:

  • You must have access to an Ubuntu 24.04 system and the ability to run commands as a non-root user with sudo privileges.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Checking the Default Git Version on Ubuntu 24.04

Ubuntu 24.04 comes with Git pre-installed, but it may not be the most recent release. Use the steps below to check the existing version before deciding to upgrade.

Display the Pre-installed Git Version

To see which version of Git is already present:

Console
$ git --version

The output should resemble:

Console
git version 2.43.0

Check Git Help Page

Run the basic Git command to confirm the help interface displays correctly:

Console
$ git

You should see output like:

Code
usage: git [-v | --version] [-h | --help] [-C ] [-c =]
           [--exec-path[=]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=] [--work-tree=] [--namespace=]
           [--config-env==]  []

These are common Git commands used in various situations:
........

If Git is missing or the installed version is outdated, continue with the instructions below to upgrade to the latest version.

Installing Git via APT on Ubuntu 24.04

Git is part of Ubuntu’s default APT repositories. Use these steps to add the Git PPA and install the most current version:

Add the Official Git PPA

Console
$ sudo add-apt-repository ppa:git-core/ppa

Update APT Cache

Console
$ sudo apt update

Install Git

Console
$ sudo apt install git -y

This command installs the newest Git version, overwriting the default installation.

Install the Complete Git Toolkit

To include all auxiliary tools, use the following command:

Console
$ sudo apt install git-all

Confirm the Git Version

Console
$ git --version

The version output should look like:

Console
git version 2.48.1

Installing a Specific Git Version from Source

In certain scenarios, it’s beneficial to compile a specific Git version for added compatibility. Follow the instructions below to install Git from source on Ubuntu 24.04.

Install Required Dependencies

Console
$ sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc -y

Download Git Source Archive

Navigate to the Git releases page and download the version you want using wget, e.g., 2.48.1:

Console
$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.48.1.tar.gz

Extract the Source Files

Console
$ tar -zxvf git-2.48.1.tar.gz

Navigate to the Extracted Directory

Console
$ cd git-2.48.1/

Compile the Source Code

Console
$ sudo make prefix=/usr/local all

Install Compiled Git

Console
$ sudo make prefix=/usr/local install

Verify the Installed Version

Console
$ git --version

Configuring Git

Before making commits, Git must be configured with your name and email. This ensures all commits are correctly attributed.

Set Global Git Username

Console
$ git config --global user.name "Your Full Name"

Set Global Git Email

Console
$ git config --global user.email "email@example.com"

Check Current Git Settings

Console
$ git config --list

You should see output like:

Code
user.name=Your Full Name
user.email=email@example.com

Manually Edit Git Configuration

If desired, you can open the configuration file and make edits directly:

Console
$ nano ~/.gitconfig

How to Use Git on Ubuntu 24.04

To begin using Git in your local development environment on Ubuntu 24.04, follow the steps below.

Create a Project Directory

Start by setting up a new folder for your project, such as demo-project:

Console
$ mkdir demo-project

Enter the Project Directory

Console
$ cd demo-project

Create a Sample File

Create a simple text file using the echo command:

Console
$ echo "Greetings from centron, Git Works!!" > file.txt

Initialize a Git Repository

Set up a new Git repository in the current folder:

Console
$ git init

Stage Files for Commit

Use this command to add all files in the directory to the staging area:

Console
$ git add .

Or add a specific file manually:

Console
$ git add file.txt

Create a Git Commit

To create a commit with all added or changed files:

Console
$ git commit -m "First Commit" -a

The -a flag commits all changes automatically. Output may look like:

Code
1 file changed, 1 insertion(+)
create mode 100644 file.txt

Commit Specific Files

To commit individual files:

Console
$ git commit -m "Initial Commit" file.txt

Review Commit History

Console
$ git log

Check Repository Status

Use this to see changes, staged or untracked files:

Console
$ git status

Add Remote Repository

Link your repository to a remote server (replace the URL accordingly):

Console
$ git remote add origin <remote-repository-url>

Verify Remotes

Console
$ git remote -v

Push Local Changes to Remote

Push commits to the main branch:

Console
$ git push origin main

Ensure you have permission to write to the remote before pushing.

Pull Updates from Remote

Console
$ git pull origin main

Display All Branches

Console
$ git branch -a

Example output:

Code
* master

The asterisk marks the current active branch. /remotes/origin/master shows a single master branch is available remotely.

Create a New Branch

Use the following to create a branch named demo-branch:

Console
$ git checkout -b demo-branch

Expected output:

Code
Switched to a new branch 'demo-branch'

Branches help separate environments—useful for development vs. production workflows.

Switch Between Branches

Console
$ git checkout demo-branch

Check the Current Branch

Console
$ git branch

Expected output:

Code
* demo-branch
  master

Return to Master Branch

Console
$ git checkout master

Output:

Code
Switched to branch 'master'

Merge Branches

Merge demo-branch into the current branch:

Console
$ git merge master --no-ff

Push Your Changes

Console
$ git push origin

Clone a Repository

Download a remote Git repo to your local machine:

Console
$ git clone https://github.com/nginx/nginx

Upgrade Git on Ubuntu 24.04

You can upgrade your Git installation to the most recent version using APT.

Check the Current Git Version

Console
$ git --version

Update System Packages

Console
$ sudo apt update

Install the Updated Git Package

Console
$ sudo apt install git -y

If the Git PPA is already added, this command installs the latest stable version available.

Verify the Upgrade

Console
$ git --version

Conclusion

You’ve successfully installed Git on Ubuntu 24.04, configured your environment, and worked with repositories and commits. Using the official Git PPA ensures you have access to the latest version. Refer to the Git documentation for further setup and advanced options.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren