On this page
- Which Git release comes with each distribution?
- How do you install Git with the package manager?
- Can you get a newer Git on Ubuntu?
- How do you tell Git who you are?
- Which defaults make daily work smoother?
- How do you reach remote repositories over SSH?
- What about HTTPS remotes and tokens?
- How do you prove the installation works?
- Which first-run errors are common and how do you fix them?
- Questions
Which Git release comes with each distribution?
Every image we offer already has a recent Git in its package repositories, so the distribution package is the right choice for almost every server. The versions differ a little between systems:
- Ubuntu 24.04: Git 2.43 in the main archive, with security fixes backported by the distribution.
- Ubuntu 22.04: Git 2.34, older but still maintained.
- Debian 12: Git 2.39; Debian 13: Git 2.47.
- Rocky Linux 9 and AlmaLinux 9: Git 2.4x from AppStream, refreshed with each minor release.
All of these support the modern commands used in this guide series, such as git switch, git restore and init.defaultBranch. To see what your mirror offers before you install, ask the package manager:
# Ubuntu and Debian
apt policy git
# Rocky Linux and AlmaLinux
dnf info gitLog in as a normal user with sudo rights first. If you only have root so far, follow the first SSH session tutorial and the sudo user guide before you continue.
How do you install Git with the package manager?
One command installs Git and its helpers; the package pulls in curl and OpenSSH client libraries it needs for HTTPS and SSH remotes.
# Ubuntu 24.04 / 22.04, Debian 12 / 13
sudo apt update
sudo apt install -y git
# Rocky Linux 9, AlmaLinux 9
sudo dnf install -y gitConfirm the binary is on your path and see which release you got:
git --version
which gitThe output looks like git version 2.43.0. Some extras live in separate packages: git-lfs for large binary files, git-email for sending patches by mail and gitk for a graphical history viewer, which you will rarely want on a headless server. Install them only when a project asks for them.
Can you get a newer Git on Ubuntu?
Yes. The Git maintainers publish a stable PPA for Ubuntu that tracks the latest upstream release, which helps when a tool needs a feature added after 2.43.
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update
sudo apt install -y git
git --versionOn Debian, Rocky and Alma stay with the distribution package unless you have a concrete reason; the packaged versions receive security patches automatically through unattended updates, while a hand-built Git in /usr/local would be yours to patch forever.
How do you tell Git who you are?
Set a name and an email once per user account; Git writes them into every commit you create, and it refuses to commit until both exist.
git config --global user.name "Deploy User"
git config --global user.email "deploy@example.net"
git config --global init.defaultBranch main
git config --global core.editor nanoThese values go into ~/.gitconfig. Git reads settings from three levels and the most specific one wins:
- --system:
/etc/gitconfig, for every user on the machine. - --global:
~/.gitconfig, for your user. - --local:
.git/configinside one repository, handy when a single project needs a different email.
To list everything in effect together with the file each value came from, run git config --list --show-origin. If you prefer Vim over nano, set core.editor vim; the nano guide covers the basics of the simpler editor.
Which defaults make daily work smoother?
A handful of extra settings remove common surprises, especially on a server where several people may push.
git config --global pull.rebase false
git config --global fetch.prune true
git config --global push.autoSetupRemote true
git config --global rerere.enabled true
git config --global color.ui auto
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --decorate --all"- pull.rebase false keeps the classic merge behaviour and silences the hint Git prints on every pull; set it to
trueif your team prefers a straight history. - fetch.prune removes references to branches that were deleted on the remote.
- push.autoSetupRemote (Git 2.37 and later, so not on Ubuntu 22.04 without the PPA) lets a first
git pushcreate the upstream branch for you. - rerere remembers how you resolved a conflict and replays that resolution the next time the same conflict shows up.
For files you never want committed in any project, such as editor swap files, point Git at a personal ignore list:
printf "*.swp\n.env.local\n" >> ~/.gitignore_global
git config --global core.excludesFile ~/.gitignore_globalHow do you reach remote repositories over SSH?
Create an ed25519 key pair for the server user, then register the public half with your Git host or with the account that owns the bare repository. SSH remotes never prompt for a password once the key is in place.
ssh-keygen -t ed25519 -C "deploy@198.51.100.24"
cat ~/.ssh/id_ed25519.pubPaste the printed line into the SSH keys page of Forgejo, Gitea, GitLab or whichever service hosts your code. For a repository on another of your own servers, append it to ~/.ssh/authorized_keys of the user there. A short entry in ~/.ssh/config saves typing:
Host code
HostName git.example.net
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesNow git clone code:team/app.git works, and ssh -T code tests the login. The SSH keys and hardening tutorial explains key handling in more depth. Keys you add on the console SSH keys page are written to new servers at deploy time; they are separate from the keys a server uses to talk to a Git host.
What about HTTPS remotes and tokens?
HTTPS remotes work too, but most hosts reject account passwords and expect a personal access token instead. Git can keep that token in memory for a while so you do not paste it on every push:
git config --global credential.helper "cache --timeout=3600"The alternative helper store writes the token to ~/.git-credentials in plain text. Use it only on a single-user server, keep the file at mode 600, and prefer a token with read-only scope when the server only needs to pull. For automation, a deploy key (an SSH key that grants access to one repository) is usually the cleaner option.
How do you prove the installation works?
Build a throwaway repository, commit a file and read the history back; if each step succeeds, Git and your identity settings are ready.
mkdir -p ~/git-test && cd ~/git-test
git init
echo "hello from $(hostname)" > README.md
git add README.md
git commit -m "First commit"
git log --stat
git branch --show-currentThe log should show your name and email, and the branch should be main. Remove the folder afterwards with rm -rf ~/git-test. From here, the clone, commit, push and pull guide walks through working with a real remote.
Which first-run errors are common and how do you fix them?
Most early problems come from missing identity, missing keys or file ownership.
- "Please tell me who you are": the
user.nameoruser.emailsetting is empty for this user. Run the twogit config --globallines again, without sudo, as the user that commits. - "Permission denied (publickey)": the remote does not know your public key, or SSH offers a different one. Run
ssh -vT git@git.example.netand look for which key file is tried. - "detected dubious ownership in repository": the repository belongs to another user, often because it was cloned with sudo. Fix the owner with
sudo chown -R deploy:deploy /srv/app, or trust that path explicitly withgit config --global --add safe.directory /srv/app. - Host key verification failed: the first connection needs you to accept the host key. Connect once with
sshinteractively, or add it withssh-keyscan git.example.net >> ~/.ssh/known_hostsafter checking the fingerprint.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install and configure Git
Does Git need a lot of memory or disk on a VPS?
No. The client itself is small. Repository size is what counts: a large history with binary assets can take gigabytes, and cloning very big repositories briefly uses extra memory while Git unpacks objects.
Should I install Git as root?
Install the package with sudo, but run your daily git commands as a normal user such as deploy. Repositories cloned as root end up owned by root, which leads to permission and ownership warnings later.
How do I keep Git up to date?
Normal system updates handle it: sudo apt upgrade or sudo dnf upgrade. If you added the Ubuntu PPA, those updates also bring new upstream releases.
Can one server use different identities for work and personal projects?
Yes. Keep a global default and override it per repository with git config user.email inside that project, or use includeIf sections in ~/.gitconfig to switch identity by folder.
Is the GitLab image a replacement for installing Git?
The GitLab CE image gives you a full web Git host with its own Git inside. You still install the plain Git client on any other server that clones from it.