How to Install Git on Debian

Install Git on Debian 11, 12, or 13 with sudo apt install git, optionally pull a newer release from backports or build from the official kernel.org tarball, set user.name and user.email, verify with git --version, update through apt, and remove cleanly.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

Install Git on Debian hero with DEBIAN GUIDE badge, git version control graphics, and apt install feature highlights

Git is the distributed version control system behind the Linux kernel, most open-source projects, and everyday git clone / git push workflows. Debian includes Git in its main archive, so a normal desktop or server can install the CLI with one apt command and receive security fixes through the same upgrade path as the rest of the system.

This guide covers install Git on Debian for Debian 11 (Bullseye), 12 (Bookworm), and 13 (Trixie): install with apt, optionally pull a newer packaged build from backports, build upstream Git from the official kernel.org source directory, configure your identity, run a first commit, update, and uninstall. I ran these steps on Debian 13 and kept real terminal output below.

Tested on: Debian 13 (trixie); kernel 6.12.94+deb13-amd64; amd64; Git 2.47.3 via apt; Git 2.54.0 via source build under /opt/git-2.54.0.

NOTE
The official Git install page recommends your distribution package manager on Linux. Use a source build only when you need a feature or bugfix from a newer upstream release than Debian (or backports) ships.

Choose an install method

Method Best for Updates
apt install git Servers, desktops, CI runners (recommended) sudo apt upgrade or sudo apt install --only-upgrade git
Backports Older stable releases when a newer packaged Git exists Same apt workflow against the backports suite
Source tarball (kernel.org) Workstations that need the current upstream tag Manual rebuild when you choose

Most readers should use apt. Debian maintains the package, dependencies, and security support. Keep the Pro Git — Installing Git source instructions for the rare case where upstream moves ahead of your release.


Check your current Git

Before installing, see whether Git is already present and which package Debian offers:

bash
. /etc/os-release && echo "$PRETTY_NAME"
git --version 2>/dev/null || echo "git: not installed"
command -v git 2>/dev/null || true
apt-cache policy git

On Debian 13 with Git already installed:

text
Debian GNU/Linux 13 (trixie)
git version 2.47.3
/usr/bin/git
git:
  Installed: 1:2.47.3-0+deb13u1
  Candidate: 1:2.47.3-0+deb13u1

Typical default versions by release (check packages.debian.org/git for the current revision):

Debian release Upstream version (git --version)
Debian 13 (trixie) 2.47.x
Debian 12 (bookworm) 2.39.x
Debian 11 (bullseye) 2.30.x

Upstream stable at the time of writing is 2.54.0 (git-scm.com). That gap is normal on stable distributions—only switch to backports or source when your project actually needs a newer Git.


The Git project’s Linux install page documents Debian/Ubuntu installation as:

bash
sudo apt update
sudo apt install -y git

On my host apt install reported:

text
Setting up git (1:2.47.3-0+deb13u1) ...
Processing triggers for man-db (2.13.1-1) ...

Verify the binary and package:

bash
git --version
which git
dpkg -l git
text
git version 2.47.3
/usr/bin/git
ii  git  1:2.47.3-0+deb13u1  amd64  fast, scalable, distributed revision control system

apt installs the core client plus dependencies such as git-man. Optional GUI and integration packages (git-gui, gitk, git-email) are separate—install them when you need them, or use the git-all metapackage if you want the full set from packages.debian.org.

Prerequisites: sudo and working apt sources (deb.debian.org or your mirror).


Install a newer Git from backports (optional)

On an older stable release, Debian Backports sometimes ships a newer git package before the next Debian release. Follow Debian Backports — Instructions and the Debian Wiki — Backports.

Example for bookworm (adjust the suite name for your release):

bash
echo 'deb http://deb.debian.org/debian bookworm-backports main' | \
  sudo tee /etc/apt/sources.list.d/bookworm-backports.list
sudo apt update
apt-cache policy git

If a backports candidate appears, install it explicitly:

bash
sudo apt install -y git/bookworm-backports
git --version

Search backports.debian.org before enabling backports—not every release backports Git. When no backports entry exists, use the source method below or stay on the default apt package.


Build Git from the official source tarball

Use this when you need the current upstream release and Debian’s package (and backports, if any) is too old. The Pro Git book lists the build dependencies for Debian-based systems:

bash
sudo apt install -y build-essential libcurl4-gnutls-dev libexpat1-dev \
  gettext libssl-dev zlib1g-dev ca-certificates curl xz-utils

Create a build directory and download the latest stable tarball from kernel.org:

bash
mkdir -p ~/git-build && cd ~/git-build
GIT_VERSION=2.54.0
curl -fLO "https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.xz"
tar -xf "git-${GIT_VERSION}.tar.xz"
cd "git-${GIT_VERSION}"

Compile and install under a versioned prefix (keeps files separate from Debian’s apt package):

bash
make -j"$(nproc)" prefix="/opt/git-${GIT_VERSION}" all
sudo make prefix="/opt/git-${GIT_VERSION}" install
sudo ln -sfn "/opt/git-${GIT_VERSION}/bin/git" /usr/local/bin/git
hash -r

On my VM the compile step took several minutes. Near the end of make install:

text
install -d -m 755 '/opt/git-2.54.0/bin'
install -m 755 git '/opt/git-2.54.0/bin/git'

Verify which binary your shell uses:

bash
command -v git
readlink -f "$(command -v git)"
git --version
/usr/bin/git --version
text
/usr/local/bin/git
/opt/git-2.54.0/bin/git
git version 2.54.0
git version 2.47.3

/usr/local/bin normally precedes /usr/bin on Debian, so git runs the source build while the apt package remains at /usr/bin/git for rollback.

IMPORTANT
Do not remove the apt git package just to “avoid confusion” unless you manage updates yourself. Keeping both lets you switch back by removing the /usr/local/bin/git symlink.

Release tarballs and tags are also listed on the official Git repository on GitHub; kernel.org is the canonical download location cited in the Pro Git book.


Configure Git on Debian

Git runs without global configuration, but commits require user.name and user.email. Set them once per account (see git config global for more options):

bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main

Confirm:

bash
git config --global --get user.name
git config --global --get user.email
git config --global --get init.defaultBranch
text
Your Name
[email protected]
main

Settings live in ~/.gitconfig. Omit --global inside a single repository when that project needs a different identity.


Create a test repository

After install and configuration, confirm Git can initialize, stage, and commit:

bash
mkdir -p /tmp/git-debian-test && cd /tmp/git-debian-test
git init -b main
printf 'hello\n' > README.md
git add README.md
git commit -m "Initial commit"
git status
git log --oneline -1
text
Initialized empty Git repository in /tmp/git-debian-test/.git/
[main (root-commit) ea4fca2] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
On branch main
nothing to commit, working tree clean
ea4fca2 Initial commit

For day-to-day commands after this smoke test, see the git init tutorial. Python workflows that clone from GitHub also assume a working git binary—see install Python package from GitHub.


Update Git

Apt-installed Git updates with the rest of the system:

bash
sudo apt update
sudo apt upgrade

Upgrade only Git when a new Debian revision is available:

bash
sudo apt update
sudo apt install --only-upgrade git

Source-built Git does not update through apt. Download a newer tarball from kernel.org, rebuild under /opt/git-NEWVERSION, and move the /usr/local/bin/git symlink. Remove old /opt/git-* directories when you no longer need them for rollback.


Uninstall Git

Match removal to how you installed.

Remove the apt package:

bash
sudo apt remove git
sudo apt autoremove
dpkg -l git | grep '^ii' || echo 'apt git package is not installed'

Remove a source build (only when /usr/local/bin/git points into /opt/git-*):

bash
readlink -f /usr/local/bin/git

If the path is under /opt/git-2.54.0 (replace with your version):

bash
sudo rm -f /usr/local/bin/git
sudo rm -rf /opt/git-2.54.0
hash -r
command -v git || git --version

After removing the symlink, git resolves to /usr/bin/git again if the apt package is still installed.

User-level files (~/.gitconfig, ~/.git-credentials) are not removed by apt remove. Delete them only when you no longer need that identity or cached credentials.


Troubleshooting

Symptom Likely cause Fix
git: command not found Package not installed or symlink missing sudo apt install git or recreate the /usr/local/bin/git symlink for source builds
fatal: unable to access 'https://…': SSL certificate problem Stale or missing CA bundle sudo apt install --reinstall ca-certificates
Please tell me who you are on commit Missing user.name / user.email Run the git config --global commands in the configuration section
[email protected]: Permission denied (publickey) SSH key not on the hosting account See fatal: Could not read from remote repository
git --version still shows the apt release after source install PATH prefers /usr/bin hash -r; confirm command -v git is /usr/local/bin/git

References


Summary

Install Git on Debian with sudo apt update && sudo apt install -y git for almost every server and workstation—Debian’s package is maintained, integrates with ca-certificates and OpenSSH, and updates through normal apt upgrades. When an older stable release needs a newer packaged Git, enable backports and install git/RELEASE-backports if backports.debian.org lists one. Build from the kernel.org tarball only when you need the current upstream tag; install under /opt/git-VERSION and symlink /usr/local/bin/git so the apt copy stays available at /usr/bin/git. Set user.name, user.email, and init.defaultBranch before your first real commit.


Frequently Asked Questions

1. How do I install Git on Debian?

Run sudo apt update && sudo apt install -y git, then verify with git --version. Debian ships Git in the main archive—no third-party repository is required for the standard command-line client.

2. What version of Git does Debian install by default?

It depends on the release. Debian 13 (trixie) ships Git 2.47.x, Debian 12 (bookworm) 2.39.x, and Debian 11 (bullseye) 2.30.x. Run apt-cache policy git before installing to see the candidate on your system.

3. Should I install git or git-all on Debian?

Install git for the core CLI used by most workflows. The git-all metapackage also pulls optional tools such as git-gui and gitk. The official Git project documents apt-get install git for Debian and Ubuntu on git-scm.com/install/linux.

4. How do I get a newer Git than my Debian release provides?

Check whether git exists in your release backports suite (backports.debian.org), then apt install git/RELEASE-backports after enabling backports. For the current upstream tag, build from the kernel.org source tarball per the Pro Git installing guide.

5. How do I configure Git after installing on Debian?

Set git config --global user.name and user.email before your first commit, and git config --global init.defaultBranch main for new repositories. Values are stored in ~/.gitconfig.

6. Why does git --version show an old number after a source build?

Your shell is running the apt binary at /usr/bin/git because /usr/local/bin is not first on PATH, or the symlink was never created. Run command -v git and readlink -f "$(command -v git)" to see the active binary.

7. How do I update Git installed from apt on Debian?

Run sudo apt update && sudo apt upgrade, or sudo apt install --only-upgrade git to refresh only the Git package when a security or point release is published.

8. How do I uninstall Git from Debian?

For apt: sudo apt remove git and optionally sudo apt autoremove. For a source build under /opt/git-VERSION, remove the /usr/local/bin/git symlink and sudo rm -rf /opt/git-VERSION. User settings in ~/.gitconfig are separate—delete them only when you no longer need that identity.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …