How to Install Git on Debian 11

How to Install Git on Debian 11

Git is a DevOps tool used to manage the source code on small or large projects.

The open-source project was initially developed in 2005 by Linus Torvalds.

Git’s version control system lets you push code to host code platforms such as Github, BitBucket, and Gitlab.

It lets you perform code management tasks such as reverting to previous versions, branching, etc.

There may be many developers working on software. Git allows you to track the commits done in branches before merging them into the master for release.

In this tutorial, you learn how to install and configure Git on Debian 11 server.

Method 1: Installing Git using APT Package Manager

We first update Debian's package index. Run the following command-

$ sudo apt update

Now, you can install Git package from Debian's APT repository

$ sudo apt install git

Once the installation is done, check the Git version-

$ git --version

Installing Git using APT Package Manager

The output can show that you have installed Git version 2.30.2

Method 2: Installing Git from Source

You can also install Git from the source, which is a more flexible method. It allows you to have the latest version of the Git repository.

Install all the Git dependencies -

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

After the installation is complete, go to the Git project hosted on Github.

https://github.com/git/git

Go to the 'Master' branch and select the 'Tags' link.

Choose the latest Git option from the top of the panel.

Avoid selecting the release candidate version that has the suffix rc. It is a beta version which may not be that stable.

You can select the latest release mentioned on the menu. For this tutorial, we use Git v2.33.0, which we install on Debian.

Installing Git from Source for Debian 11

Click on the 'Code' button and then copy the 'Download ZIP' link as shown below-

Installing Git from Source for Debian 11

On the 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

Now you can unzip the compressed file.

$ unzip git.zip

Navigate into the uncompressed directory with the following command -

$ cd git-2.33.0

Install the file from the source using the following commands:

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

After the installation, you can verify that you now have the latest version of Git.

$ git --version

How to Install Git from Source for Debian 11

How to Set Up Git

Now, we have Git installed on Debian 11 Server. You have to set up Git, so that commit messages have the correct information.

You have to add the name and email address embedded in the commit messages. To do so, run the following git config commands.

$ git config --global user.name "Winnie"
$ git config --global user.email "Winnie@xyz.com"

To verify that the configuration has been set up, run the command shown below -

$ git config --list

How to Set Up Git in Debian 11

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

$ cat ~/.gitconfig

Summary

Git allows programmers to collaborate on the source code during software development.

It supports distributed non-linear workflows. Such workflows may have thousands of parallel branches running on different systems.

You can track the changes in any set of files using Git. It lets you review incorrect commits and revert to a previous version.

The tutorial has covered how to set up Git for Debian 11. You can use the two methods to install and then configure Git on the Debian operating system.

For more tutorials on Debian, check out CloudPanel tutorials.

Nikita S.
Nikita S.
Technical Writer

As a lead technical writer, Nikita S. is experienced in crafting well-researched articles that simplify complex information and promote technical communication. She is enthusiastic about cloud computing and holds a specialization in SEO and digital marketing.


Deploy CloudPanel For Free! Get Started For Free!