How to Install Git on Debian 13, 12 and 11

Last updated Tuesday, May 19, 2026 10:07 am Joshua James 8 min read

Debian’s default repositories already provide Git, so most systems can install Git on Debian with one APT command and receive fixes through normal package updates. The only real decision is whether Debian’s maintained Git version is enough for everyday commits, pulls, and pushes, or whether a project needs a newer upstream release built from source.

The base package is the Git command-line client. GitHub Desktop, GitHub CLI, and self-hosted GitLab are separate tools that build on Git rather than replacing the base package.

Install Git on Debian

Use APT unless you specifically need a Git feature newer than the package in your Debian release. Source builds work, but they move update and removal responsibility from Debian to you.

Choose the Git Installation Method

MethodSourceUpdate BehaviorBest ForTrade-offs
APT packageDebian package archiveUpdated through normal APT upgradesMost servers, desktops, CI runners, and development systemsVersion follows the Debian release branch instead of the newest upstream tag
Source buildOfficial Git source tarballsManual rebuild when a new upstream version is availableUsers who need current upstream Git or custom build controlRequires build dependencies, manual lifecycle management, and careful removal

The APT package is the safest default because Debian owns the package, dependencies, and security updates. Keep the source method for development workstations or controlled build hosts where a newer Git release is worth the extra maintenance.

Refresh Debian Package Metadata

Refresh the package index before installing Git so APT uses current repository metadata:

sudo apt update

These commands use sudo for package-management tasks that need root privileges. If your account cannot use sudo, add the user to sudoers on Debian before continuing.

Install Git with APT

Install the Debian-maintained Git package:

sudo apt install git

APT installs the main git command plus required support packages such as git-man and liberror-perl. On normal desktop or server systems, recommended packages such as certificates and SSH client support are usually already present; APT installs them if they are missing.

Verify the APT Git Package

Check the installed Git command:

git --version

Debian 13 currently reports this upstream version from the default package:

git version 2.47.3

The exact version depends on your Debian release and security updates. Current default package candidates are:

Debian ReleasePackage CandidateVersion Reported by Git
Debian 13 (Trixie)1:2.47.3-0+deb13u1git version 2.47.3
Debian 12 (Bookworm)1:2.39.5-0+deb12u3git version 2.39.5
Debian 11 (Bullseye)1:2.30.2-1+deb11u5git version 2.30.2

Package revisions such as -0+deb13u1 or -1+deb11u5 are Debian packaging revisions. The git --version command prints the upstream Git version only.

Build Current Git from Source

Use this method only when the Debian package is too old for your workflow. It installs Git under a versioned /opt/git-VERSION prefix and symlinks the active command to /usr/local/bin/git, which keeps source-built files separate from Debian-owned packages.

Do not mix a source-built Git command with the APT package unless you deliberately want both. The command your shell runs depends on PATH, so verify the active command with command -v git after installing or removing either method.

Install Source Build Dependencies

Install the compiler, headers, and download tools needed to build Git from source:

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

The dependency set provides the C/C++ toolchain, TLS support, compression support, HTTP transport support, XML parsing, translated message handling, trusted certificates, and .tar.xz extraction support.

Resolve the Latest Git Source Version

Create a build workspace and resolve the newest stable source tarball from the official kernel.org Git directory:

mkdir -p ~/git-build
cd ~/git-build

GIT_VERSION=$(curl -fsSL https://www.kernel.org/pub/software/scm/git/ | grep -oE 'git-[0-9]+\.[0-9]+\.[0-9]+\.tar\.xz' | sed -E 's/git-//; s/\.tar\.xz//' | sort -V | tail -n 1)
test -n "$GIT_VERSION"
printf 'Latest Git source version: %s\n' "$GIT_VERSION"

Current output from the official source directory resolves to:

Latest Git source version: 2.54.0

Download Git Source

Download the resolved tarball in the build workspace:

curl -fLO "https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.xz"

Kernel.org also publishes matching .tar.sign files. If your keyring already trusts the Git release-signing key, install GPG and verify the detached signature before building:

sudo apt install gpg
curl -fLO "https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.sign"
xz -dkf "git-${GIT_VERSION}.tar.xz"
gpg --verify "git-${GIT_VERSION}.tar.sign" "git-${GIT_VERSION}.tar"

GPG can verify the signature only after you have a trusted release-signing key. If GPG reports a missing or untrusted key, stop and establish key trust through an official maintainer-key process before treating the source as verified.

Extract Git Source

Extract the downloaded source archive, then enter the versioned source directory:

tar -xf "git-${GIT_VERSION}.tar.xz"
cd "git-${GIT_VERSION}"

Compile and Install Git Source

Compile Git and install it into a versioned directory under /opt:

make prefix="/opt/git-${GIT_VERSION}" all
sudo make prefix="/opt/git-${GIT_VERSION}" install

Create or update the /usr/local/bin/git symlink so the source-built command is easy to run:

GIT_SOURCE="/opt/git-${GIT_VERSION}/bin/git"
GIT_LINK="/usr/local/bin/git"

if [ ! -x "$GIT_SOURCE" ]; then
  printf 'Source-built Git not found at %s\n' "$GIT_SOURCE" >&2
elif [ -e "$GIT_LINK" ] && [ ! -L "$GIT_LINK" ]; then
  printf 'Refusing to replace non-symlink %s\n' "$GIT_LINK" >&2
else
  sudo ln -sfn "$GIT_SOURCE" "$GIT_LINK"
  hash -r
fi

Verify Source-Built Git

Confirm that your shell finds the source-built command and that Git reports the expected version:

command -v git
git --version
git --exec-path

Expected output for the current upstream release looks like this:

/usr/local/bin/git
git version 2.54.0
/opt/git-2.54.0/libexec/git-core

Configure Git on Debian

Git can run without global configuration, but commits need an author name and email. Set global values for your user account before creating commits on this system.

Set Your Git Name and Email

Replace the example values with the name and email address you want stored in new commits:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The --global flag writes the setting to ~/.gitconfig. Omit --global inside a repository when one project needs a different identity, or use the dedicated Git username and email configuration reference for more examples.

Set the Default Branch Name

Set main as the initial branch name for new repositories:

git config --global init.defaultBranch main

New repositories created with git init now start on main, which matches current defaults on common hosting platforms. For existing repositories, use the separate workflow to rename a local and remote Git branch.

Verify Git Configuration

Print the configured values that Git will use for new commits:

git config --global --get user.name
git config --global --get user.email
git config --global --get init.defaultBranch

Example output:

Your Name
you@example.com
main

Use Git for a First Repository

After installation and identity setup, create a small test repository to confirm that Git can initialize, stage, and commit files from your user account.

Initialize a Repository

Create a project directory and initialize Git inside it:

mkdir my-project
cd my-project
git init

Git creates a hidden .git directory that stores repository metadata, history, branches, and configuration.

Check Repository Status

Check the working tree and staging area:

git status --short

A new empty repository has no output from git status --short. New or modified files appear with compact status markers.

Stage and Commit a File

Create a small file, stage it, and commit it:

printf 'hello\n' > README.md
git add README.md
git commit -m "Initial commit"

The commit succeeds when your Git identity is configured. If you commit too early, set your name and email, then rerun the commit command; if the wrong commit was created, follow the workflow to undo the last Git commit before pushing it.

Connect to a Remote Repository

Add a remote repository URL after creating the matching repository on your hosting service:

git remote add origin https://github.com/example-user/example-repo.git
git push -u origin main

The -u flag stores the upstream relationship so later pushes can use plain git push. When another clone updates the remote branch, bring those changes back with:

git pull origin main

Cache HTTPS Credentials Temporarily

For HTTPS remotes, Git can cache credentials in memory for a limited time:

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

This keeps credentials in memory for 5 hours. SSH keys or a dedicated credential manager are better choices for long-term authentication on development systems.

Update or Remove Git on Debian

Update and removal steps must match the method you used. APT owns Debian packages, while source builds installed under /opt need explicit rebuilds and cleanup.

Update APT-Installed Git

Normal package upgrades update Git along with the rest of your Debian packages:

sudo apt update
sudo apt upgrade

To upgrade only Git when a newer Debian package is available, use:

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

Update Source-Built Git

A source build does not update through APT. Create a helper that resolves the latest source tarball, rebuilds it under /opt, and moves the /usr/local/bin/git symlink after the install succeeds:

mkdir -p ~/git-build
cat > ~/git-build/update-git-from-source.sh <<'EOF'
#!/bin/bash
set -euo pipefail

INSTALL_BASE="/opt"
LINK_PATH="/usr/local/bin/git"
BUILD_DIR="$HOME/git-build"

latest_version() {
  curl -fsSL https://www.kernel.org/pub/software/scm/git/ |
    grep -oE 'git-[0-9]+\.[0-9]+\.[0-9]+\.tar\.xz' |
    sed -E 's/git-//; s/\.tar\.xz//' |
    sort -V |
    tail -n 1
}

GIT_VERSION=$(latest_version)

if [ -z "$GIT_VERSION" ]; then
  printf 'Could not resolve the latest Git source version.\n' >&2
  exit 1
fi

printf 'Latest Git source version: %s\n' "$GIT_VERSION"

if [ -e "$LINK_PATH" ] && [ ! -L "$LINK_PATH" ]; then
  printf 'Refusing to replace non-symlink %s\n' "$LINK_PATH" >&2
  exit 1
fi

CURRENT_VERSION="none"
if [ -x "$LINK_PATH" ]; then
  CURRENT_VERSION=$("$LINK_PATH" --version | sed -E 's/^git version //')
fi

printf 'Current source Git version: %s\n' "$CURRENT_VERSION"

if [ "$CURRENT_VERSION" = "$GIT_VERSION" ]; then
  printf 'Git is already current: %s\n' "$CURRENT_VERSION"
  exit 0
fi

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
rm -rf "git-${GIT_VERSION}" "git-${GIT_VERSION}.tar" "git-${GIT_VERSION}.tar.sign" "git-${GIT_VERSION}.tar.xz"
printf 'Downloading Git %s source...\n' "$GIT_VERSION"
curl -fLo "git-${GIT_VERSION}.tar.xz" "https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.xz"

if [ "${VERIFY_GIT_SOURCE_SIGNATURE:-0}" = "1" ]; then
  curl -fLo "git-${GIT_VERSION}.tar.sign" "https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.sign"
  xz -dkf "git-${GIT_VERSION}.tar.xz"
  gpg --verify "git-${GIT_VERSION}.tar.sign" "git-${GIT_VERSION}.tar"
fi

tar -xf "git-${GIT_VERSION}.tar.xz"
cd "git-${GIT_VERSION}"

printf 'Building Git %s...\n' "$GIT_VERSION"
make prefix="${INSTALL_BASE}/git-${GIT_VERSION}" all
printf 'Installing Git %s under %s...\n' "$GIT_VERSION" "${INSTALL_BASE}/git-${GIT_VERSION}"
sudo make prefix="${INSTALL_BASE}/git-${GIT_VERSION}" install
SOURCE_GIT="${INSTALL_BASE}/git-${GIT_VERSION}/bin/git"

if [ ! -x "$SOURCE_GIT" ]; then
  printf 'Source-built Git not found at %s\n' "$SOURCE_GIT" >&2
  exit 1
fi

sudo ln -sfn "$SOURCE_GIT" "$LINK_PATH"
hash -r
printf 'Updated source-built Git:\n'
"$LINK_PATH" --version
EOF

Make the helper executable, then run it whenever you want to check for an upstream Git update:

chmod +x ~/git-build/update-git-from-source.sh
~/git-build/update-git-from-source.sh

When the source-built Git command already matches the latest upstream tarball, the helper stops before downloading or compiling:

Latest Git source version: 2.54.0
Current source Git version: 2.54.0
Git is already current: 2.54.0

On a first source install or a real update, the build produces compiler output. Relevant lines include:

Latest Git source version: 2.54.0
Current source Git version: none
Downloading Git 2.54.0 source...
Building Git 2.54.0...
Installing Git 2.54.0 under /opt/git-2.54.0...
Updated source-built Git:
git version 2.54.0

If your keyring already trusts the release-signing key and gpg is installed, run the helper with signature verification enabled:

VERIFY_GIT_SOURCE_SIGNATURE=1 ~/git-build/update-git-from-source.sh

If the release-signing key is missing from your trusted keyring, GPG stops the helper before the build begins. A relevant line includes:

gpg: Can't check signature: No public key

Run source-build updates manually. Compilation can fail because of missing dependencies, network failures, or upstream build changes, and you want to see those errors before changing the active Git command.

Remove APT-Installed Git

Remove the Debian package when you no longer need Git from APT:

sudo apt remove git

Preview unused dependencies before removing them, especially on development systems where another package may still need the same tools:

apt -s autoremove

If the preview only lists packages you no longer need, remove them:

sudo apt autoremove

Confirm the APT package is no longer installed:

dpkg -l git | grep '^ii' || printf 'APT git package is not installed\n'

Remove Source-Built Git

If you used the /opt/git-VERSION source method, remove the active source-built prefix only after checking where the symlink points:

readlink -f /usr/local/bin/git

For the current example, the path should look like:

/opt/git-2.54.0/bin/git

Remove only a path that starts with /opt/git-:

The next command deletes the active source-built Git prefix under /opt. Check the readlink output first, and keep any older /opt/git-* directory you still need for rollback.

GIT_LINK=/usr/local/bin/git

if [ -L "$GIT_LINK" ]; then
  GIT_REAL=$(readlink -f "$GIT_LINK")
  GIT_PREFIX=$(dirname "$(dirname "$GIT_REAL")")

  case "$GIT_PREFIX" in
  /opt/git-*)
    sudo rm -f "$GIT_LINK"
    sudo rm -rf "$GIT_PREFIX"
    ;;
  *)
    printf 'Refusing to remove unexpected Git path: %s\n' "$GIT_PREFIX" >&2
    ;;
  esac

  hash -r
else
  printf '%s is not a symlink managed by this source-build method.\n' "$GIT_LINK" >&2
fi

If older source-build prefixes remain from previous updates, list them and remove only the exact versions you no longer need:

ls -d /opt/git-* 2>/dev/null

Remove the helper script and build workspace only when you no longer need the local source tree, downloaded tarballs, or update helper:

rm -rf ~/git-build

Build dependencies such as build-essential, libssl-dev, and libcurl4-gnutls-dev may be shared by other development work. Leave them installed unless you know they were added only for this source build.

Remove User Git Configuration

User configuration can include commit identities, aliases, and saved HTTPS credentials. Back up these files before removing them if you might reuse the settings on another system.

Back up common user-level Git configuration files, then remove the originals:

mkdir -p ~/git-config-backup
cp -a ~/.gitconfig ~/.git-credentials ~/git-config-backup/ 2>/dev/null || true
rm -f ~/.gitconfig ~/.git-credentials

Troubleshoot Git on Debian

Use the symptom that matches your terminal output, then verify the fix before continuing with repository work.

Fix git Command Not Found

If the shell cannot find Git, the package is missing, the source-build symlink is missing, or the shell has cached an old path.

bash: git: command not found

Check whether any Git command is on your current PATH:

command -v git

If the command prints nothing, install the APT package or recreate the source-build symlink. For APT:

sudo apt update
sudo apt install git

For the source method, replace the version with the installed prefix under /opt:

GIT_SOURCE=/opt/git-2.54.0/bin/git
GIT_LINK=/usr/local/bin/git

if [ ! -x "$GIT_SOURCE" ]; then
  printf 'Source-built Git not found at %s\n' "$GIT_SOURCE" >&2
elif [ -e "$GIT_LINK" ] && [ ! -L "$GIT_LINK" ]; then
  printf 'Refusing to replace non-symlink %s\n' "$GIT_LINK" >&2
else
  sudo ln -sfn "$GIT_SOURCE" "$GIT_LINK"
  hash -r
  git --version
fi

Fix HTTPS Certificate Errors

HTTPS clone, fetch, or push commands can fail when CA certificates are missing or stale:

fatal: unable to access 'https://github.com/user/repo.git/': SSL certificate problem: unable to get local issuer certificate

Reinstall Debian’s certificate bundle, then retry the Git command:

sudo apt install --reinstall ca-certificates

Corporate networks may require an internal CA certificate in the system trust store. Add that certificate through your organization’s documented trust process rather than disabling TLS verification.

Fix SSH Permission Denied Errors

SSH remotes fail with this error when the hosting provider does not recognize a usable public key for your account:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Test GitHub SSH authentication directly:

ssh -T git@github.com

A working GitHub key returns a greeting similar to:

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

GitLab and other hosts return different success text. If authentication fails, generate an SSH key, add the public key to your hosting account, and confirm that OpenSSH is installed on Debian.

Fix Root-Owned Repository Files

Running Git commands with sudo inside a normal user repository can leave files owned by root. Check ownership before changing it:

ls -ld .git

If the repository metadata is owned by root, return ownership to your current user:

sudo chown -R "$(id -un):$(id -gn)" .git

Rerun ls -ld .git and confirm your username and primary group appear as the owner.

Fix the Wrong Git Version After a Source Build

If git --version still reports the Debian package after a source build, inspect the active command path:

command -v git
readlink -f "$(command -v git)"

If the command points to /usr/bin/git, the APT package is winning on PATH. Recreate the source-build symlink and clear the shell cache:

GIT_SOURCE=/opt/git-2.54.0/bin/git
GIT_LINK=/usr/local/bin/git

if [ ! -x "$GIT_SOURCE" ]; then
  printf 'Source-built Git not found at %s\n' "$GIT_SOURCE" >&2
elif [ -e "$GIT_LINK" ] && [ ! -L "$GIT_LINK" ]; then
  printf 'Refusing to replace non-symlink %s\n' "$GIT_LINK" >&2
else
  sudo ln -sfn "$GIT_SOURCE" "$GIT_LINK"
  hash -r
  command -v git
  git --version
fi

Replace 2.54.0 with the source-built version installed under /opt.

Conclusion

Git is ready on Debian with the package source that fits your maintenance model: APT for stable system-managed updates, or a source build under /opt when a project needs current upstream Git. For graphical workflows, GitHub Desktop on Debian pairs with the CLI, while GitLab on Debian is the next step when you want to host repositories yourself.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: