Git is usually one command away on Linux. This short guide covers installing it, getting a newer version when you need one, and the configuration every new machine — including servers — should have.

Install

Ubuntu / Debian:

sudo apt update
sudo apt install -y git
git --version

AlmaLinux / Rocky / Fedora:

sudo dnf install -y git

The distribution package is fine for nearly everyone, and receives security updates with the rest of the system.

Newer version on Ubuntu

The Git maintainers’ PPA tracks the latest stable release:

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install -y git

Useful if you need a recent feature; otherwise stick with the default package.

Configure your identity

Every commit records a name and email:

git config --global user.name "Alice Example"
git config --global user.email "[email protected]"

For a server that commits automatically (backups to Git, config tracking with etckeeper), use something descriptive, e.g. "web1 automation".

Sensible defaults

git config --global init.defaultBranch main
git config --global pull.rebase true          # avoid merge-commit noise on pull
git config --global fetch.prune true          # clean up deleted remote branches
git config --global core.editor nano          # or vim
git config --global color.ui auto
git config --global rerere.enabled true       # remember conflict resolutions

View everything:

git config --global --list

Settings live in ~/.gitconfig. Repository-specific settings (git config user.email … without --global) override them.

Line endings

Linux uses LF line endings. If you also work on Windows, configure Git there to convert, and keep Linux as-is:

git config --global core.autocrlf input     # on Linux/macOS

A .gitattributes file in the repository (* text=auto) gives consistent results for everyone.

Authenticate to remotes

SSH (recommended): create a key and add it to GitHub/GitLab/Gitea — see Git SSH keys.

HTTPS with a token: platforms require personal access tokens instead of passwords. Cache them so you don’t retype:

git config --global credential.helper 'cache --timeout=3600'

On desktops, the Git Credential Manager stores credentials securely. On servers, prefer read-only deploy keys over personal tokens.

Verify

mkdir -p /tmp/test-repo && cd /tmp/test-repo
git init
echo "hello" > README.md
git add README.md
git commit -m "First commit"
git log --oneline

Useful extras

sudo apt install -y git-lfs          # large files (see Git LFS)
git lfs install
sudo apt install -y tig              # text-mode history browser

Next steps

  • Git
  • Ubuntu
  • Development