How to Install Git on Debian 11

Written by: Winnie Ondara   |   Last updated: July 21, 2022

Keeping track of source code is one of the essential skills that every developer needs to have. Git is one of the DevOps tools that help developers to manage their source code - from small to large projects. Git is an open-source version control tool that allows developers to push their code to host code platforms such as Github, BitBucket, and Gitlab. It helps them to perform code management tasks such as reverting to previous versions, branching, etc.

In this tutorial, we will install and configure Git on Debian 11 server. There are two approaches to installing Git. You can install from Debian repositories using the APT package manager or install from the source which provides the latest version of Git.

Method 1: Installing Git using APT package manager

To get started, be sure to update Debian's package index.

sudo apt update

Once the update is complete, install Git from Debian's APT repository using the simple command provided.

sudo apt install git

Once the installation is done, check the version of Git:

git --version
Check Git version

The output shows we have installed Git version 2.30.2.

Method 2: Installing Git from source

A better and more flexible option is to install Git from the source. While this may be a longer path to take, it will certainly give you the latest version of Git.

To begin, install all the Git dependencies:

sudo apt update
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

Once the installation is complete, head over to the Git's project which is hosted on Github

https://github.com/git/git

Navigate to the 'Master' branch and click on the 'Tags' link and choose the latest Git option which is usually the first option from the top. Avoid selecting the release candidate version (which bears the suffix rc). This is more like a Beta version and is likely to be buggy and unstable.

At the time of writing down this guide, the latest release of Git is Git v2.33.0. This is the release that we are going to install.

Select the latest git version
Select the latest git version

At the far right, click on the 'Code' button and then copy the 'Download ZIP' option link

Clone Git repository on Github
Clone git repository on Github

Back to your Debian 11 server, download the zip file using the wget command.

wget  https://github.com/git/git/archive/refs/heads/master.zip -O git.zip

Next, unzip the compressed file.

unzip git.zip

Then navigate into the uncompressed directory.

cd git-2.33.0

Then install it from source using the following commands:

sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

Once the installation is complete, verify that you now have the latest version of Git.

git --version

How to set up Git

At this point, we have successfully installed Git on Debian 11 Server. There's one small last bit remaining. We need to set it up so that commit messages will bear our correct information.

We will provide our name and email address details which will be embedded in the commit messages. To do so, execute the following git config commands.

git config --global user.name "Winnie"
git config --global user.email "[email protected]"

To confirm that the configuration has been set up run the command:

git config --list
Configure git on Debian server
Configure git on Debian server

These details are written in the ~/.gitconfig file. You can additionally confirm by viewing the file.

cat ~/.gitconfig
git config file
git config file

Conclusion

You can now start using Git to host your code on any code hosting and collaborative platform such as Github. In this tutorial, we have walked you through the installation of Git on the Debian 11 server.

About The Author

Winnie Ondara

Winnie Ondara

Winnie is a Linux technical writer with over 3 years of experience with various Linux distributions and writing technical guides in Linux. She is passionate about FOSS technologies and always endeavor to learn new technologies. During my free time, I watch movies, listen to music, and catch up with tech news.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment