Git is a popular open-source version control system developedLinus Torvalds developed in 2005. It is designed to help developers track changes made to source code and collaborate on software development projects. Git has become the de facto standard for version control in the software development industry, with many companies and open-source projects relying on it for their development workflows.
Here are some key features of Git:
- Distributed: Unlike centralized version control systems like Subversion, Git is a distributed version control system, meaning every developer has a copy of the entire codebase. This makes working offline and collaborating with other developers easier without relying on a central server.
- Branching and merging: Git allows developers to create multiple branches of the codebase, which can be worked on independently and merged back into the main branch when ready. This makes it easier to manage complex codebases and collaborate on large projects.
- Lightweight: Git is designed to be lightweight and fast, with a small footprint and minimal dependencies. This makes it easy to install and use on a variety of platforms.
- Open-source: Git is open-source software, meaning anyone can use, modify, and contribute. This has led to a large and active community of developers constantly improving and expanding the software.
- Integration with other tools: Git can be integrated with many other tools and services, including continuous integration and deployment (CI/CD) systems, code review tools, and project management platforms.
Installing Git on Debian is a straightforward process that can be done using the command line terminal. The following guide will demonstrate how to install Git on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster.
To install Git on a Debian system, it’s recommended to first 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.
Method 1: Install Git with APT
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:
This should display the version of Git that you just installed.
Method 2: Install Git by Compiling Source
For those who want to install the latest version of Git, it’s recommended to install it from source. This allows you to quickly re-compile any urgent updates and ensures you have the latest version of Git installed.
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 source.
Next, you need to 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:
Note that the version number may be different when you read this.
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
Again, the version number may be different depending on which version you downloaded.
Once the archive is extracted, navigate to the extracted directory using the cd command. For example:
Run the following command to build Git from source:
make prefix=/usr/local all
This command compiles the source code and creates the executable files that make up 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.
Finally, verify that Git has been installed successfully by running the following command:
This should display the version of Git that you just installed.
Command Git Command Examples
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:
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.
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 and used to manage code and other digital assets. By using the proper commands, users can commit, push, and pull changes to and from remote repositories. With these tools at your disposal, managing code on a Debian system is easier and more streamlined.