UGC bg

How to install and configure Git on Ubuntu 22.04

Install and configure Git on Ubuntu 22.04


Git is one of the most famous Version Control System (VCS) in the world. Its wide adoption over the past years makes it an unavoidable tool in the development world.

In this tutorial, you will learn how to install and configure Git on an Ubuntu 22.04 Linux distribution.



This tutorial assumes that you have a VPS, bare metal server, or as in our case, an OVHcloud Compute Instance running Ubuntu 22.04. You should also have basic knowledge of the command line. If you need help setting up a Public Cloud instance with Ubuntu 22.04 follow the guide to use an OVHcloud Compute Instance.



In this tutorial, you will install Git, configure it, and learn how to sign your commits.

At the time of writing this tutorial, the lastest LTS release of Git was 2.36.1.


Installation of the Git LTS

To install Git on Ubuntu, use the apt-get command.
In order to have the latest LTS version, you will need to add a repository.

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


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

PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'deb jammy main'
The most current stable version of Git for Ubuntu.

For release candidates, go to .
More info:
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Found existing deb entry in /etc/apt/sources.list.d/git-core-ubuntu-ppa-jammy.list
Adding deb entry to /etc/apt/sources.list.d/git-core-ubuntu-ppa-jammy.list
Found existing deb-src entry in /etc/apt/sources.list.d/git-core-ubuntu-ppa-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/git-core-ubuntu-ppa-jammy.list
Adding key to /etc/apt/trusted.gpg.d/git-core-ubuntu-ppa.gpg with fingerprint E1DD270288B4E6030699E45FA1715D88E1DF1F24
Hit:1 jammy InRelease
Hit:2 jammy-updates InRelease                    
Get:3 jammy-backports InRelease [99.8 kB]                              
Ign:4 binary/ InRelease                                                                                                 
Hit:5 binary/ Release                                                                                     
Hit:6 jammy InRelease       
Hit:7 jammy-security InRelease                 
Fetched 99.8 kB in 1s (112 kB/s)
Reading package lists... Done

Install Git using the apt-get command:

sudo apt-get update && sudo apt-get -y install git


$ sudo apt-get update && sudo apt-get -y install git

Hit:1 jammy InRelease
Hit:2 jammy-updates InRelease                                       
Hit:3 jammy-security InRelease                                                 
Get:4 jammy-backports InRelease [99.8 kB]                           
Hit:5 jammy InRelease                                       
Ign:6 binary/ InRelease                                                     
Hit:7 binary/ Release
Fetched 99.8 kB in 1s (113 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following packages will be upgraded:
  git git-man
2 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.
Need to get 7700 kB of archives.
After this operation, 8810 kB of additional disk space will be used.
Get:1 jammy/main amd64 git amd64 1:2.36.1-0ppa1~ubuntu22.04.1 [5768 kB]
Get:2 jammy/main amd64 git-man all 1:2.36.1-0ppa1~ubuntu22.04.1 [1933 kB]
Fetched 7700 kB in 0s (22.9 MB/s)
(Reading database ... 131441 files and directories currently installed.)
Preparing to unpack .../git_1%3a2.36.1-0ppa1~ubuntu22.04.1_amd64.deb ...
Unpacking git (1:2.36.1-0ppa1~ubuntu22.04.1) over (1:2.34.1-1ubuntu1.2) ...
Preparing to unpack .../git-man_1%3a2.36.1-0ppa1~ubuntu22.04.1_all.deb ...
Unpacking git-man (1:2.36.1-0ppa1~ubuntu22.04.1) over (1:2.34.1-1ubuntu1.2) ...
Setting up git-man (1:2.36.1-0ppa1~ubuntu22.04.1) ...
Setting up git (1:2.36.1-0ppa1~ubuntu22.04.1) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...                                                                                             
Scanning candidates...                                                                                            
Scanning linux images...                                                                                          

Restarting services...
 systemctl restart irqbalance.service jenkins.service packagekit.service polkit.service postgresql@14-main.service qemu-guest-agent.service ssh.service udisks2.service
Service restarts being deferred:
 systemctl restart ModemManager.service
 systemctl restart networkd-dispatcher.service
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

Verify the installation and display the Git version:

git --version


$ git --version

git version 2.36.1


Basic configuration: name and email

Once Git is installed, it is recommended that you make some configurations. In particular, the identification associated with your commits. Rather than having to make this configuration for each repository, it's possible to make a global configuration using a .gitconfig file located in the root folder of the home user.

This file can be made manually or by using the config option with the git command:

git config --global "Firstname Lastname" git config --global ""

Display your .gitconfig file in your home directory:

cat .gitconfig


$ cat .gitconfig
	name = Firstname Lastname
	email =


Advanced configuration: signed commits

It is strongly recommended that you sign your commits. The reason for this is to ensure that you are the owner of the commit and not someone pretending to be you. As you have seen before, the name and email are readable by everyone on remote repositories like GitHub or GitLab. Anyone can enter the same data and claim to be you. To prevent this, the gpg tool is used to create a public cryptography key that is used to verify that the origin of a commit is genuine.

All commands will use the gpg utility, already installed on Ubuntu.

Ggenerate the key:

gpg --generate-key


$ gpg --generate-key

gpg (GnuPG) 2.2.27; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note: Use "gpg --full-generate-key" for a full featured key generation dialog.

GnuPG needs to construct a user ID to identify your key.

Real name: Firstname Lastname
Email address:
You selected this USER-ID:
    "Firstname Lastname <>"

Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key BECE6D85FDA1B6C8 marked as ultimately trusted
gpg: directory '/home/ubuntu/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/ubuntu/.gnupg/openpgp-revocs.d/18E345A3F27325A8B4816875BECE6D85FDA1B6C8.rev'
public and secret key created and signed.

pub   rsa3072 2022-06-17 [SC] 
uid                      Firstname Lastname <>
sub   rsa3072 2022-06-17 [E] 

Verify the generated key:

gpg --list-secret-keys --keyid-format=long


$ gpg --list-secret-keys --keyid-format=long

gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2024-06-16
sec   rsa3072/ABCDEFGHIJKLMNOP 2022-06-17 [SC] 
uid                 [ultimate] Firstname Lastname <>
ssb   rsa3072/ZZZZZZZZZZZZZZZZ 2022-06-17 [E] 

 Add the key to your Git configuration in the .gitconfig file in your home repository:

git config --global commit.gpgsign true git config --global gpg.program gpg git config --global user.signingkey ABCDEFGHIJKLMNOP

Extract and copy your key to your remote Git provider (GitLab, GitHub, ButBucket, …):

gpg --armor --export ABCDEFGHIJKLMNOP


$ gpg --armor --export ABCDEFGHIJKLMNOP




That’s it, you have successfully installed and configured Git on Ubuntu 22.04.