How to Install & Configure Git on Debian 11

Git is a mature, actively maintained open source project initially developed in 2005 by Linus Torvalds, the famous Linux operating system kernel creator. Git is designed for developers that need a pretty straightforward version control system. Most software is collaborative efforts and sometimes can have hundreds of people with commits working on software development projects. It’s essential to track these commits customarily done in branches in most projects before being merged into the master for release. It is easy to review and track down any incorrect commits and revert, leading to a much easier development if anything goes wrong.

The following tutorial will learn how to install Git on Debian 11 Bullseye with various methods.

Advertisement

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo or root access.
  • Required Packages: various listed in the tutorial

Update Operating System

Update your Debian operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@debian~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Debian.

To use the root account, use the following command with the root password to log in.

su

Install Git using APT Package Manager

By default, Git is available in the Debian Bullseye repository, installed using the APT package manager. To do this, use the following command:

sudo apt install git

Example of dependencies that will be installed:

How to Install & Configure Git on Debian 11

Type (Y,) then press (ENTER KEY) to proceed with the installation.

Once installed, verify the installation:

git --version

Example output:

git version 2.30.2
Advertisement

Install Git from Experimental Repository

An alternative solution for users wanting one of the latest versions of Git while still using the APT package manager is to install Git from the Debian experimental repository.

First, open up the file /etc/apt/sources.list:

sudo nano /etc/apt/sources.list

Add the following:

deb http://deb.debian.org/debian experimental main contrib non-free
deb-src http://deb.debian.org/debian experimental main contrib non-free

Save the file (CTRL+O), then exit (CTRL+X).

Note, be careful you haven’t got these already, and you will soon find out when you use the apt update command, and you get an error output having multiple. Do not stress; open up the file, remove the double up, and re-use the apt update command if you encounter this.

Update your repository listing with the following command:

sudo apt update

Now install the Git package from unstable:

sudo apt install git -t experimental

Note, you may see a prompt as follows:

How to Install & Configure Git on Debian 11

This is a message informing you certain services will need rebooting. For the majority of users, this will be fine to select the <Yes> option. Choose and finalize the installation of Git.

Verify the installation and check the build:

git -version

Example output:

git version 2.33.0.309.g3052b89438

You will notice the stable build is v2.30.2, and the experimental build is v2.33.0, which is often the latest or not far behind what is available from the official Git repository.

Another optional extra you can do is track the Git package installed using the experimental repository. This means when you invoke the update command, it will track and inform you if an upgrade is available automatically.

To do this, first, open up your /etc/apt/preferences file:

sudo nano /etc/apt/preferences

Next, to avoid conflicts such as updating your default Debian 11 repository packages to that from experimental, you can set APT pinning. You will always draw with apt update command Git from the experimental repository automatically. Secondly, all packages will be set to be installed or updated from Bullseye with a priority score of 500. Thirdly any packages not in Debian 11 default repository will be installed or updated from Experimental with a lower priority score of 100.

This method of APT pinning keeps the system clean and without confusion, bugs, and conflicts.

Package: git
Pin: release a=experimental
Pin-Priority: 1000

Package: *
Pin: release a=bullseye
Pin-Priority: 500

Package: *
Pin: release a=experimental
Pin-Priority: 100

Save the file, CTRL+O, then exit CTRL+X, and now you can track any future updates.

Advertisement

Compile & Install Git from Source

The tutorial has covered how to install stable or unstable using the APT package manager. However, for those wanting the absolute latest Git version, it’s recommended to always install from the source.

As with unstable, you will need to make sure any security issues are monitored; with the source, you can quickly re-compile any urgent updates making this the better option for anyone needing to use the latest Git.

Before starting the installation from the source, use the su command to log into the root account for this installation.

To begin with, install the Git dependencies as follows:

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

Example dependencies that will be installed:

How to Install & Configure Git on Debian 11

Type (Y,) then press “ENTER KEY” to proceed with the installation.

Once the dependencies are installed, visit the release page to find the master zip archive or the latest stable release from Git.

At the time of writing the guide, 3.3.0 is the latest stable release. Use the wget command as below:

wget https://github.com/git/git/archive/refs/tags/v2.33.0.zip

Use the wget command to get the latest development version (master):

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

Note, do not use this version unless as it will be unstable and possibly contain bugs.

Next, Unzip which archive you downloaded:

Example:

sudo unzip v2.33.0.zip

Now you will need to navigate to the directory using the CD command:

cd git-2.33.0

You now need to run the following make commands to install git:

First command:

sudo make prefix=/usr/local all

Second command:

sudo make prefix=/usr/local install

Now that you have installed Git from the source, verify the installation and build:

git -version

Example output:

git version 2.33.0

You will notice this version is ahead of both the Debian repository stable, testing, and often unstable. If you want true bleeding edge Git, the source is the best place to acquire this.

How to Configure Git

After installation, you will need to set up standard settings such as names and e-mails, mainly around git commit messages. This is pretty straight forward as the tutorial will explain below.

The first step is to provide your name that will be set Globally:

git config --global user.name "YOUR NAME"

Next, select your e-mail; this can fake if you prefer:

git config --global user.email "YOUR EMAIL"

To confirm these have been added, use the config –list command:

git config --list

Example below:

How to Install & Configure Git on Debian 11

Unless specified, Git stores details in the ~/.gitconfig file. You can review what is currently stored by using the cat command:

cat ~/.gitconfig

Example below:

How to Install & Configure Git on Debian 11

Note, using the sudo command with the git config command will set two separate user names and e-mails.

You can store this information for quicker access in the future; note this is for dedicated servers being run by 1 or 2 people that are trustworthy as the information isn’t stored securely or encrypted and is just in text form, so any users that have access to the server can easily read this.

git config --global credential.helper cache

If you must use credential helper, it is advised to cache only for a limited time for increased security. For example, you will be working today using git for 1 to 4 hours but won’t be touching it for maybe a few weeks, then set expiry for 5 hours:

git config --global credential.helper "cache --timeout=18000"

After 5 hours, the credentials will be deleted. This secures your GIT.

Comments and Conclusion

Git is a fantastic piece of software for software developers and even sys admins. Web server owners can track changes on specific directories when developing your servers or website, and the ability to quickly revert should not be looked over. Git is not the most accessible software to work. However, it works well for what it is designed for.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
adplus-dvertising
0
Would love your thoughts, please comment.x
()
x