Install and Configure Git on Linux
| Ubuntu / Debian / Mint | sudo apt install git |
| Fedora | sudo dnf install git (often preinstalled) |
| Arch | sudo pacman -S git |
| openSUSE | sudo zypper install git |
| Config files | ~/.gitconfig (user), .git/config (repository), /etc/gitconfig (system) |
| Check version | git --version |
| Documentation | git-scm.com/doc, man git, git help <command> |
Install Git
# Ubuntu, Debian, Linux Mint, Raspberry Pi OS
sudo apt update
sudo apt install git
# Fedora
sudo dnf install git
# Arch
sudo pacman -S git
# openSUSE
sudo zypper install git
# check
git --version
Fedora and Arch track recent upstream releases. Debian stable and Ubuntu LTS keep the version from release day with security fixes, which is fine for nearly everyone. If you need a newer feature on Ubuntu or Mint, use the official Git maintainers' PPA:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Useful extras: git-lfs for large binary files, gitk and git-gui for simple graphical views, and gh (GitHub CLI) or glab (GitLab CLI) where your distribution packages them.
First-time configuration
Git records a name and email in every commit. Set them once for your user:
git config --global user.name "Alex Doe"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global core.editor "nano" # or vim, "code --wait"
git config --global pull.rebase false # merge on pull (or true to rebase)
git config --global fetch.prune true # drop deleted remote branches
git config --list --show-origin
Use the email address your Git host associates with your account (GitHub and GitLab offer a private "noreply" address) so commits link to your profile. For one repository with a different identity, such as work, run the same commands inside it without --global.
Line endings: on Linux leave core.autocrlf unset, or set it to input if you work with files from Windows, so CRLF never gets committed:
git config --global core.autocrlf input
Authenticate to GitHub, GitLab and others
SSH keys (recommended)
ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub # paste this into your Git host's SSH keys settings
ssh -T [email protected] # test (or [email protected])
git clone [email protected]:user/repo.git
Example output:
Hi alex! You've successfully authenticated, but GitHub does not provide shell access.
The full walkthrough, including passphrases and ssh-agent, is in setting up SSH keys. If the test fails, see Permission denied (publickey). To switch an existing clone from HTTPS to SSH:
git remote -v
git remote set-url origin [email protected]:user/repo.git
HTTPS with a token
Git hosts no longer accept your account password for Git over HTTPS; use a personal access token instead. To avoid typing it each time, use a credential helper:
# keep credentials in memory for an hour
git config --global credential.helper 'cache --timeout=3600'
# or let the GitHub CLI manage it
gh auth login
Fedora packages git-credential-libsecret, which stores tokens in the desktop keyring (GNOME Keyring or KWallet):
sudo dnf install git-credential-libsecret
git config --global credential.helper libsecret
credential.helper store saves tokens in plain text in ~/.git-credentials. Use it only on single-user machines with an encrypted disk, and prefer SSH keys or a keyring-backed helper.
Sign commits with your SSH key
Git can sign commits with an SSH key instead of GPG, which most hosts display as "Verified":
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
git config --global tag.gpgsign true
Add the same public key to your Git host again, this time as a signing key. To verify signatures locally, create an allowed-signers file:
echo "[email protected] $(cat ~/.ssh/id_ed25519.pub)" >> ~/.config/git/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
git log --show-signature -1
Create ~/.config/git/ first with mkdir -p ~/.config/git if it doesn't exist.
Common tasks
git clone [email protected]:user/repo.git
git status
git add file.txt # or git add -p to stage hunks
git commit -m "Describe the change"
git push
git pull
git switch -c feature-x # new branch
git log --oneline --graph --all
A global ignore file keeps editor and OS clutter out of every repository:
printf '.vscode/\n*.swp\n.DS_Store\n' >> ~/.config/git/ignore
Git reads ~/.config/git/ignore automatically. For the rest of the everyday commands (undoing changes, stashing, rebasing, tags), see the Git commands cheat sheet.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
fatal: detected dubious ownership in repository | Repository owned by another user (copied as root, external drive, container mount) | Fix ownership with sudo chown -R $USER: repo or mark it safe; see dubious ownership |
Permission denied (publickey) | Key not added to the host or not offered | ssh -vT [email protected]; see the fix page |
Support for password authentication was removed | Account password used over HTTPS | Use a token, gh auth login, or switch to SSH |
Author identity unknown | Name/email not set | Set user.name and user.email (above) |
REMOTE HOST IDENTIFICATION HAS CHANGED when pushing | Host key changed or stale entry in known_hosts | Verify the new fingerprint with the host's docs; see the fix page |
git: command not found | Git not installed | Install it (above); see command not found |
| Every line shows as changed | Line endings or file mode changes | core.autocrlf input; git config core.fileMode false on filesystems without Unix permissions |
For any command, GIT_TRACE=1 git <command> prints what Git is doing, and GIT_SSH_COMMAND="ssh -v" git fetch shows the SSH negotiation.
Frequently asked questions
How do I check which Git version is installed?
Run git --version. If it prints command not found, Git isn't installed; install the git package with your package manager.
How do I get the latest Git on Ubuntu?
Ubuntu LTS releases keep the Git version they shipped with, plus security fixes. For the newest upstream release, add the Git maintainers' PPA: sudo add-apt-repository ppa:git-core/ppa, then sudo apt update && sudo apt install git.
Why does GitHub reject my password over HTTPS?
GitHub no longer accepts account passwords for Git operations. Use SSH keys, a personal access token as the password, or the GitHub CLI (gh auth login) to set up credentials.
Where is the global Git config file?
In ~/.gitconfig, or ~/.config/git/config if you create that instead. git config --list --show-origin shows every setting and which file it comes from.
Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.