How to install Git on Debian 13

Learn how to install Git on Debian 13

In this blog post, we will explain how to install Git on Debian 13 OS. Git is a free and open-source distributed version control system that manages the code changes in files among multiple developers. The main characteristic of Git is its distributed nature, which means that every developer has a complete copy of the entire project locally. Git stores the data in a series of snapshots known as commits made at specific points in time. Among these, Git offers branching and Merging, which allow developers to work independently on different tasks for the same project.

Installing Git is a straightforward process, and its installation time depends on which method is used. In this tutorial, we are going to cover both methods for installation, from source and from the default repository. Let’s get started!

Prerequisites

Update the system

Before we start with the installation of GIT, we need to update the packages to their latest available versions. To do that, execute the following command:

sudo apt update -y && sudo apt upgrade -y

Install Git from the default Repository

The easiest and fastest way to install Git is to use the default Debian 13 repository. To do that, you can simply execute the following command:

sudo apt install git -y

To check the installed version, execute the command below:

git --version

You should get output similar to this:

root@host:~# git --version
git version 2.47.2

Now you have installed a Git version provided by the default Debian 13 repository. If you want to install a specific Git version, you will have to download and build it from source, which will be explained in the next heading.

Install Git from source

As we explained above, sometimes we need a specific Git version to install. For that, we will download it, compile, and build the Git version from source. Building Git from source requires installation prerequisites, which can be installed with the following command:

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

Once these prerequisites are installed, we can download the desired Git version. Let’s download a slightly lower version than the version we installed in the previous heading.

cd /opt

wget https://github.com/git/git/archive/refs/tags/v2.44.1.tar.gz

Extract the compressed file first and then enter the extracted folder:

tar -xvf v2.44.1.tar.gz

cd git-2.44.1/

To build Git from source, execute the command below:

sudo make prefix=/usr/local all

The building process will begin, and it is expected to take around 5 minutes to complete.

root@host:/opt/git-2.44.1# sudo make prefix=/usr/local all
GIT_VERSION = 2.44.1
    * new build flags
    CC oss-fuzz/dummy-cmd-main.o
    CC oss-fuzz/fuzz-commit-graph.o
    CC oss-fuzz/fuzz-date.o
    CC oss-fuzz/fuzz-pack-headers.o
    CC oss-fuzz/fuzz-pack-idx.o
    CC daemon.o
    .
    .

Once the installation files are built and compiled, we can proceed with the installation. Execute the command below:

sudo make prefix=/usr/local install

The command will install Git very fast, and then we need to create a symbolic link:

ln -s /usr/local/bin/git /usr/bin/git

Then we can check the installed Git version:

git --version

You should get the following output:

root@host:~# git --version
git version 2.44.1

Basic Git Commands

Here are some basic Git commands used on a daily basis:

git init — Initializes a new Git repository in the current directory. 

git clone — Creates a local copy of an existing Git repository. 

git status — Displays the current state of the working directory and staging area. 

git add — Stages changes (files) so they’ll be included in the next commit. 

git commit — Records the staged changes in the repository’s history. 

git log — Shows the history of commits in a branch. 

git diff — Displays differences between working files and the latest commit. 

git branch — Lists, creates, or deletes branches (managing parallel development lines). 

git checkout — Switches between branches or restores files to a previous state. 

git merge — Integrates changes from one branch into the current branch. 

git remote — Manages and lists remote repository links. 

git pull — Fetches updates from a remote repository and merges them into the current branch. 

git push — Uploads local commits to a remote repository. 

git rebase — Rewrites commit history by applying commits onto a new base. 

git reset — Reverts the current branch to a previous state, potentially discarding commits or moves. 

git show — Reveals information about a specific Git object (like a commit). 

git commit --amend — Modifies the most recent commit (e.g., to correct messages or add files).

Conclusion

The installation process of Git depends on the way you choose, and it can be done in a couple of minutes or a couple of seconds. However, Git is the most widely used version control system, primarily among developers. With its performance, flexibility, ease of use, and ability to track file states, we can confidently say that it is the best version control system.

Congratulations! You successfully installed Git in different ways on Debian 13 OS and learned some basic Git commands.

Of course, you do not have to install it on your own if you have difficulties and are not familiar with Linux. All you have to do is sign up for one of our NVMe VPS plans and submit a support ticket. Our admins are available 24/7 and will help you with any aspect of installing Git.

If you liked this post on installing Git on Debian 13, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment