Git config: configure Git your way
Before you start using Git, you need to configure it. Name, email, editor, aliases: this page explains how to customize Git so it works the way you want.
The 3 configuration levels
Git manages configuration at three levels. The most specific level always takes priority.
--system
Applies to all users on the machine. Rarely modified manually.
/etc/gitconfig--global
Applies to all repos on your account. This is the most commonly used level for personal config.
~/.gitconfig--local
Applies only to the current repo. Useful for having a different work email per project.
.git/configGit config in practice
Essential setup and creating aliases to save time.
Basic configuration
Aliases and overview
Essential configuration settings
user.nameYour name, displayed in every commit. Required to commit.
git config --global user.name "Your Name"user.emailYour email, associated with every commit. Use the one from your GitHub account.
git config --global user.email "your@email.com"core.editorThe editor Git opens (for commit messages, interactive rebase, etc.).
git config --global core.editor "code --wait"init.defaultBranchThe default branch name when running git init. The modern convention is "main".
git config --global init.defaultBranch mainpull.rebaseEnables automatic rebase during git pull, for a linear history.
git config --global pull.rebase truealias.*Create shortcuts for long commands. Essential for working faster.
git config --global alias.st statusConfiguration tips
Set up your name and email first
This is required to commit. Do it once with --global and it's set for all your projects.
Use --local for work projects
If you have a personal email set globally, use --local in your work projects to associate your professional email.
Create aliases from the start
Aliases like git st, git co and git lg will save you time every day.
Back up your .gitconfig
The ~/.gitconfig file contains all your global config. Save it in a "dotfiles" repo to restore your setup on a new machine.
Part of the Git Advanced guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git config
Configure Git and start practicing
Once Git is configured, dive into GitQuest investigations to learn commands in real-world scenarios.
Start the investigations