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):
sudo apt updatesudo apt install gitOn Ubuntu only, the git-core/ppa PPA provides the latest stable version of
Git:
sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt install gitsudo dnf install gitOn macOS, Git is often preinstalled with the Xcode Command Line Tools. Check first whether it is already there:
git --versionIf it is not installed, macOS offers to install it. You can also install it with Homebrew to get the latest version:
brew install gitDownload the installer from the official website: git-scm.com/download/win.
Run the installer and keep the default options. The installation includes Git Bash, a terminal that lets you use the same commands as on Linux.
You can also install Git with winget (Windows Package Manager):
winget install --id Git.Git -e --source wingetCheck the installation
Whatever your platform, check that Git is correctly installed:
git --versionExpected output:
git version 2.47.3Understand 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.
| Level | Scope | File | Option |
|---|---|---|---|
| System | All users of the machine | /etc/gitconfig | --system |
| Global | Your user account | ~/.gitconfig | --global |
| Local | A 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:
git config --list --show-originExpected output (example):
file:/home/bob/.gitconfig user.name=Stéphane ROBERTfile:/home/bob/.gitconfig user.email=stephane@example.comfile:/home/bob/.gitconfig core.editor=code --waitfile:/home/bob/.gitconfig init.defaultbranch=mainfile:.git/config core.repositoryformatversion=0file:.git/config core.filemode=truefile:.git/config core.bare=falsefile:.git/config core.logallrefupdates=trueThe --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.
-
Set your name:
Terminal window git config --global user.name "Your Name" -
Set your email:
Terminal window git config --global user.email "you@example.com" -
Check the configuration:
Terminal window git config user.namegit config user.emailExpected output:
Your Nameyou@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:
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.
git config --global core.editor "nano"git config --global core.editor "vim"Check the stored value:
git config --global core.editorExpected output:
code --waitConfigure 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:
git config --global init.defaultBranch mainWithout 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):
git config --global alias.st statusgit config --global alias.co switchgit config --global alias.ci commitgit config --global alias.br branchgit config --global alias.lg "log --oneline --graph --all --decorate"With these aliases, you can type:
git st # instead of git statusgit co main # instead of git switch maingit lg # visual log with branchesTry the lg alias, which draws the history with its branches:
git lgExpected 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 commitEach 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.
SSH configuration (recommended)
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.
-
Check whether a key already exists:
Terminal window ls -la ~/.ssh/id_ed25519.pubIf the file exists, you already have a key. Skip to step 3.
-
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.
-
Copy the public key:
Terminal window cat ~/.ssh/id_ed25519.pubCopy the whole output and add it to the SSH settings of your Git service (GitHub: Settings → SSH and GPG keys → New SSH key).
-
Test the connection:
Terminal window ssh -T git@github.comExpected output:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Summary of the recommended configuration
Here are all the configuration commands in a single sequence:
# Identitygit config --global user.name "Your Name"git config --global user.email "you@example.com"
# Editorgit config --global core.editor "code --wait"
# Default branchgit config --global init.defaultBranch main
# Useful aliasesgit config --global alias.st statusgit config --global alias.co switchgit config --global alias.ci commitgit config --global alias.br branchgit config --global alias.lg "log --oneline --graph --all --decorate"Troubleshooting: common problems
| Symptom | Likely cause | Solution |
|---|---|---|
git: command not found | Git is not installed or not in the PATH | Reinstall Git. On Linux, check with which git |
| Commits with the wrong email | user.email not set, or set at the wrong level | git config --global user.email "right@example.com" |
| The editor does not open at commit | core.editor not set, or the editor is not in the PATH | Check that the editor can be launched from the command line |
permission denied (publickey) on push | SSH key not set up or not added to the platform | Check with ssh -T git@github.com and add the key |
| Local config overrides global config | Normal: the local level takes priority over global | Use 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.nameanduser.emailbefore your first commit. - Recommended editor: set
core.editorso you do not end up stuck invi. - Default branch: use
mainwithinit.defaultBranch. - SSH recommended: it saves you from typing your password at every push/pull.
- Aliases:
git lg(graphical log) andgit 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
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
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: The Git model: snapshots, SHA and the 3 states
A new full quiz with random questions
Work again only on the questions you missed