The guide walks you through installing Git on a fresh Debian 11 machine, starting with an `apt update` to pull the latest package lists so that the version you install isn’t stale. Once Git is installed, it shows how to verify the binary, set global identity information for commits, and optionally enable credential caching or use SSH keys for remote hosting services like GitHub or GitLab. The tutorial also includes a quick look at checking your configuration file origins with `git config --list --show-origin` and hints about pulling a newer Git build from Debian backports if you need features beyond the shipped version. Finally, it wraps everything up in a concise one‑liner that covers updating, installing, and configuring user details for immediate use.
Install and Configure Git in Debian 11
If you’re setting up a fresh Debian 11 workstation, this guide shows exactly how to get Git installed and ready to use without the usual headaches.
Get the Latest Package Lists First
sudo apt update
Why bother? The apt update command pulls down the newest lists of packages from your configured repositories. Without it, apt install git might grab an outdated or even corrupted package file that could break your build scripts.
Install Git with APT
sudo apt install -y git
The Debian 11 repository ships a solid version of Git (2.30 at the time of writing). For most developers this is plenty; if you need bleeding‑edge features, we’ll cover installing from source later. The -y flag skips the confirmation prompt—perfect for scripts or when you’re in a hurry.
Verify the Installation
git --version
You should see something like git version 2.30.1. If you get a “command not found” error, double‑check that /usr/bin/git exists and that your $PATH includes it (you can run echo $PATH to confirm).
Set Your Global Identity
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Why is this important? Every commit you make records who authored it. Without these settings, Git will either ask each time or refuse to commit altogether on some configurations. I once saw a junior dev on Debian 11 try to push code and hit “Please tell me who you are.” A quick config saves the day.
Configure Credential Caching (Optional but Handy)
git config --global credential.helper cache
This keeps your credentials in memory for 15 minutes by default, so you won’t be prompted every time you push. If you prefer a longer timeout, tweak it:
git config --global credential.helper 'cache --timeout=3600'
Set Up SSH Keys for GitHub or GitLab
1. Generate a key pair
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter to accept the default file location and set a passphrase if you’re paranoid.
2. Start the SSH agent
eval "$(ssh-agent -s)"
3. Add your key
ssh-add ~/.ssh/id_ed25519
4. Copy the public key to your clipboard
On Debian, you can use xclip or simply open the file and copy manually:
cat ~/.ssh/id_ed25519.pub
5. Add it to GitHub/GitLab – paste the contents into the “SSH keys” section of your account settings.
6. Test the connection
ssh -T git@github.com
You should see a friendly welcome message. If you get “Permission denied,” double‑check that the key is correctly added and that the agent is running.
Check Your Configuration
git config --list --show-origin
This command tells you where each setting came from (global, system, or repository). It’s useful for debugging when a commit goes to the wrong email address.
Optional: Install a Newer Git via Backports
Debian 11’s backports repository contains newer package versions. If you need Git 2.37, add the line deb http://deb.debian.org/debian bullseye-backports main to /etc/apt/sources.list, run sudo apt update, then:
sudo apt install -t bullseye-backports git
Note that pulling from backports can introduce dependency issues if you’re on a tightly coupled environment, so use with caution.
TL;DR – One‑Line Commands
sudo apt update && sudo apt install -y git git config --global user.name "Your Name" git config --global user.email "you@example.com"
That’s all it takes to have a working Git setup on Debian 11.