How to Install Git on Debian 12, 11 or 10

Git, crafted by Linus Torvalds in 2005, is a cornerstone in open-source version control systems. Designed to meticulously track source code alterations and bolster collaboration on software endeavors, Git has solidified its position as the go-to version control tool in the software development sector. If you aim to harness its capabilities on a Debian system, this guide will show how to install Git on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster. Let’s delve deeper into the distinctive features that make Git indispensable for developers.

Key Features of Git:

  • Distributed System: Git’s decentralized nature ensures every developer possesses a full codebase copy. This decentralization facilitates offline work and collaboration without a central server’s dependency.
  • Branching & Merging: Git’s branching capability allows for independent codebase versions. These can seamlessly merge, streamlining codebase management and extensive project collaborations.
  • Efficiency: Git’s design emphasizes speed and efficiency, ensuring quick operations and compatibility across various platforms.
  • Open-Source Advantage: Being open-source, Git encourages global collaboration. This collective effort has cultivated a vibrant developer community dedicated to its enhancement.
  • Tool Integration: Git’s versatility extends to its integration capabilities, compatible with CI/CD systems, code review platforms, and project management tools.

Understanding Git’s robust features can enhance software development processes and collaborative efforts. With the intro covered, let’s learn two methods to install Git on your Debian desktop or server.

Install Git on Debian 12, 11, or 10 via APT

Step 1: Update Debian Before Git Installation

To install Git on a Debian system, it’s recommended first to update your system with the latest packages to avoid conflicts. Run the following command to update your system:

sudo apt update && sudo apt upgrade

This command updates your system and ensures that all existing packages are up-to-date.

Step 2: Install Git on Debian via APT Command

Next, you can install Git using the APT package manager by running the following command:

sudo apt install git

This installs the Git package from the Debian default repository.

Once installed, verify the installation:

git --version

This should display the version of Git that you just installed.

Install Git on Debian 12, 11, or 10 via the source

For those who want to install the latest version of Git, installing it from the source is recommended. This lets you quickly re-compile any urgent updates and ensures you have the latest version of Git installed.

Step 1: Install Initial Packages For Git Installation

First, you need to install the Git build dependencies by running the following command:

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

This command installs the necessary dependencies for building Git from the source.

Step 2: Download the Git source archive

Next, you must visit the Git release page and download the source code. You can use the wget command to download the latest stable release Tar archive. For example, to download the latest stable release, you can run the following command:

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

Note that the version number may be different when you read this.

Step 3: Extract Git from the source archive:

After downloading the source code, you need to extract the tar archive. You can do this by running the following command:

tar -xvf v2.40.0.tar.gz

Remember these commands are examples, replace the “2.40.0” with your version number as it will differ.

Once the archive is extracted, navigate to the extracted directory using the cd command. For example:

cd git-2.40.0

Step 4: Build and Install Git on Debian via source

Run the following command to build Git from the source:

make prefix=/usr/local all

This command compiles the source code and creates the executable files that comprise Git. The prefix=/usr/local option specifies the installation directory for the compiled software.

Once the compilation is complete, run the following command to install Git:

sudo make prefix=/usr/local install

This command copies the necessary files to the appropriate locations on your system so that you can use Git.

Step 5: Verify Git installation via source

Finally, verify that Git has been installed successfully by running the following command:

git -version

This should display the version of Git that you just installed.

Git Command Examples on Debian 12, 11, or 10

The following parts will cover some typical setups and commands used daily by users of GIT.

To set up your name and email in Git, use the following commands:

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

These commands will configure your name and email for Git commit messages.

To create a new directory for Git, use the following commands:

mkdir example-directory
cd example-directory
git init

These commands will create a new directory for Git and initialize it.

To check your Git configuration details, use the following commands:

git config --list
cat ~/.gitconfig

These commands will show you the configuration details stored in Git.

To store Git credentials, you can enable the credential helper cache using the following commands:

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

These commands will allow Git to cache your credentials for a limited time to increase security.

To view the status of a Git repository, use the following command:

git status

This command will show you the status of your Git repository.

To connect to a remote Git repository, use the following command:

git remote add origin remote-repository-link

This command will allow you to sync and download/upload changes to the remote repository.

To commit changes in your Git directory, use the following command:

git commit -m "git message changelog"

This command will allow you to commit your changes with a message in the changelog.

To push changes to the remote repository, use the following command:

git push origin master

This command will allow you to push your changes to the remote repository to sync both versions.

To pull changes from the remote repository, use the following command:

git pull origin master

This command will allow you to pull changes from the remote repository to sync both versions.

Conclusion

Installing Git on Debian is a simple process that can be done using either the APT package manager or by compiling the source code. With APT, users can install the stable version of Git easily, while compiling the source code provides access to the latest version of Git. Once installed, Git can be configured to manage code and other digital assets. Users can commit, push, and pull changes to and from remote repositories using the proper commands. With these tools, managing a Debian system’s code is easier and more streamlined.

Leave a Comment