Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Install and configure Git on Linux, macOS and Windows

By updated

Improve this page

This guide installs Git, then configures it for everyday use. You end up with a working Git, your identity recorded, your editor linked to it and a few aliases to type less.

Prerequisites: you have understood the Git model (snapshots, 3 states). No software is required beforehand.

What you will learn

  • Install Git on Linux, macOS and Windows
  • Configure your identity (the name and email attached to your commits)
  • Choose your editor for commit messages
  • Understand the 3 configuration levels (system, global, local)
  • Create aliases for the most frequent commands

Install Git

On Debian and Ubuntu, apt installs the version your distribution ships (Git 2.47.3 on Debian 13):

Terminal window
sudo apt update
sudo apt install git

On Ubuntu only, the git-core/ppa PPA provides the latest stable version of Git:

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

Check the installation

Whatever your platform, check that Git is correctly installed:

Terminal window
git --version

Expected output:

git version 2.47.3

Understand the 3 configuration levels

Git uses a configuration system with 3 levels, from the widest to the most specific. Each level can override the values of the previous one.

LevelScopeFileOption
SystemAll users of the machine/etc/gitconfig--system
GlobalYour user account~/.gitconfig--global
LocalA single repository.git/config--local

In practice, you mostly use --global for your personal settings and --local for the exceptions specific to one project.

View the current configuration

To display your whole configuration and see where each value comes from:

Terminal window
git config --list --show-origin

Expected output (example):

file:/home/bob/.gitconfig user.name=Stéphane ROBERT
file:/home/bob/.gitconfig user.email=stephane@example.com
file:/home/bob/.gitconfig core.editor=code --wait
file:/home/bob/.gitconfig init.defaultbranch=main
file:.git/config core.repositoryformatversion=0
file:.git/config core.filemode=true
file:.git/config core.bare=false
file:.git/config core.logallrefupdates=true

The --show-origin option shows the source file of each setting. It is essential for debugging configuration conflicts.

Configure your identity

The first thing to do after installing is to set your name and your email. Git writes them into every commit you create, and a commit that already exists keeps the identity of its time: changing these settings only fixes the following commits.

  1. Set your name:

    Terminal window
    git config --global user.name "Your Name"
  2. Set your email:

    Terminal window
    git config --global user.email "you@example.com"
  3. Check the configuration:

    Terminal window
    git config user.name
    git config user.email

    Expected output:

    Your Name
    you@example.com

user.name and user.email are the only two settings to set before working. Everything else (editor, colors, aliases) is optional: if you are short on time, stop here.

Configure your editor

When Git needs you to write a message (commit, merge, rebase), it opens a text editor. By default, it is often vi or nano. To use your preferred editor:

Terminal window
git config --global core.editor "code --wait"

The --wait option tells Git to wait until you close the tab in VS Code before going on.

Check the stored value:

Terminal window
git config --global core.editor

Expected output:

code --wait

Configure the default branch

Since Git 2.28, you can set the name of the branch created by git init. The modern convention is to use main:

Terminal window
git config --global init.defaultBranch main

Without this setting, Git creates a branch named master. The two names are functionally identical, but main has become the standard on GitHub, GitLab and most recent projects.

Create useful aliases

Aliases create shortcuts for the commands you use most often. Here are five common aliases (the lesson Git aliases (in French) offers more):

Terminal window
git config --global alias.st status
git config --global alias.co switch
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"

With these aliases, you can type:

Terminal window
git st # instead of git status
git co main # instead of git switch main
git lg # visual log with branches

Try the lg alias, which draws the history with its branches:

Terminal window
git lg

Expected output (in a repository of three commits, here the one from the lesson view the history):

* 13b51e7 (HEAD -> main) Add the contact page
* d756a03 Create the project structure
* 4e52753 Initial commit

Each line is a commit: its abbreviated identifier, the names of the branches that point to it in parentheses, then its message. Your identifiers will be different.

To avoid typing your password at every push and pull, set up an SSH key. It is the recommended way to connect to GitHub, GitLab and other Git services.

  1. Check whether a key already exists:

    Terminal window
    ls -la ~/.ssh/id_ed25519.pub

    If the file exists, you already have a key. Skip to step 3.

  2. Generate a new key (if needed):

    Terminal window
    ssh-keygen -t ed25519 -C "you@example.com"

    Press Enter to accept the default location. Choose a passphrase to protect your key.

  3. Copy the public key:

    Terminal window
    cat ~/.ssh/id_ed25519.pub

    Copy the whole output and add it to the SSH settings of your Git service (GitHub: Settings → SSH and GPG keys → New SSH key).

  4. Test the connection:

    Terminal window
    ssh -T git@github.com

    Expected output:

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

Here are all the configuration commands in a single sequence:

Terminal window
# Identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Editor
git config --global core.editor "code --wait"
# Default branch
git config --global init.defaultBranch main
# Useful aliases
git config --global alias.st status
git config --global alias.co switch
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"

Troubleshooting: common problems

SymptomLikely causeSolution
git: command not foundGit is not installed or not in the PATHReinstall Git. On Linux, check with which git
Commits with the wrong emailuser.email not set, or set at the wrong levelgit config --global user.email "right@example.com"
The editor does not open at commitcore.editor not set, or the editor is not in the PATHCheck that the editor can be launched from the command line
permission denied (publickey) on pushSSH key not set up or not added to the platformCheck with ssh -T git@github.com and add the key
Local config overrides global configNormal: the local level takes priority over globalUse git config --list --show-origin to see where the value comes from

Key takeaways

  • 3 configuration levels: system (machine) → global (user) → local (repository). The most specific wins.
  • Identity is mandatory: set user.name and user.email before your first commit.
  • Recommended editor: set core.editor so you do not end up stuck in vi.
  • Default branch: use main with init.defaultBranch.
  • SSH recommended: it saves you from typing your password at every push/pull.
  • Aliases: git lg (graphical log) and git st (status) save time every day.

Knowledge check

Check that you have grasped the essentials of this guide. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

10 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer