In the introduction you set your name and email, the two settings every Git user needs. Git has many more settings, though, and a few minutes spent on them makes every day with Git smoother: a friendly editor for commit messages, sensible line endings, clearer output and short commands for the things you type most.
All of these are stored by git config, in plain text files you can read and edit. Settings can apply to the whole computer, to your user account or to just one repository, and Git combines them so that the most specific one wins.
In this lesson you'll learn where settings live, check what's currently set, choose the most useful options, and create aliases: your own shortcuts such as git st for git status or a beautiful one-line history graph called git lg.
Three levels of settings
| Level | Flag | Applies to | Stored in |
|---|---|---|---|
| System | --system | Every user on the computer | Git's install folder |
| Global | --global | Your user account | ~/.gitconfig |
| Local | --local (default) | One repository | .git/config |
When the same setting appears at several levels, the most specific wins: local beats global, which beats system. That lets you use your work email in work repositories and your personal email everywhere else, for example.
See every setting and where it comes from with:
git config --list --show-originUseful settings
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global color.ui autocore.editor: the editor Git opens for commit messages and merges.code --waituses VS Code; without it Git often opens Vim, which confuses many beginners.init.defaultBranch: names the first branch of new repositories.pull.rebase: tellsgit pullwhether to merge (false) or rebase (true) when your branch and the remote have both changed. Setting it removes a warning and makes behaviour predictable.color.ui auto: coloured output in terminals that support it.
Line endings
Windows ends lines with two invisible characters (CRLF), while macOS and Linux use one (LF). When people on different systems work on the same files, Git can see every line as "changed". The core.autocrlf setting fixes this:
- On Windows:
git config --global core.autocrlf true(store LF, check out CRLF). - On macOS and Linux:
git config --global core.autocrlf input(convert any CRLF to LF when committing).
Teams can also add a .gitattributes file to the repository with * text=auto, which applies the same rules for everyone regardless of their personal settings.
Aliases
An alias is your own name for a Git command:
git config --global alias.st status
git config --global alias.co switch
git config --global alias.last "log -1 HEAD"
git config --global alias.lg "log --oneline --graph --decorate --all"Now git st runs git status, and git lg draws the whole history as a compact graph. Aliases are stored in your global config file, so they work in every repository. Keep them few and memorable; their job is to save typing on commands you use dozens of times a day.
Git Config Syntax
Config commands
git config --global key value
git config --local key value
git config --get key
git config --list --show-origin
git config --global --unset key
git config --global --edit
git config --global alias.lg "log --oneline --graph --all"Git Config Summary
- Settings exist at system, global and local levels; the most specific wins.
git config --list --show-originshows every setting and its source.- Set
core.editor,init.defaultBranchandpull.rebaseto avoid surprises. - Use
core.autocrlf(or.gitattributes) to handle Windows and Unix line endings. git config --global alias.name "command"creates shortcuts such asgit lg.
Git Config Examples
Each example shows the code, the output it produces and what each part does.
Checking your settings
git config --global --list
git config --get user.email
git config --list --show-originuser.name=Sam Lee
user.email=sam@example.com
init.defaultbranch=main
sam@example.com
file:C:/Program Files/Git/etc/gitconfig core.autocrlf=true
file:C:/Users/sam/.gitconfig user.name=Sam Lee
file:C:/Users/sam/.gitconfig user.email=sam@example.com
file:C:/Users/sam/.gitconfig init.defaultbranch=mainLine-by-line explanation
- Line 1Only the global settings from your user account.
- Line 2Read a single value.
- Line 3Every setting with the file it comes from: the system file first, then the global one.
A different email for one repository
cd work-project
git config user.email "sam.lee@company.com"
git config --get user.email
cd ../hobby-project
git config --get user.emailsam.lee@company.com
sam@example.comLine-by-line explanation
- Line 2Without a level flag, git config writes a local setting for this repository only.
- Line 3Inside the work project, the local value wins.
- Line 5Elsewhere, the global email is used.
Creating and using aliases
git config --global alias.st "status --short"
git config --global alias.lg "log --oneline --graph --decorate --all"
git st
git lg M index.html
?? notes.txt
* 52ac9e1 (HEAD -> main) Add dark colour scheme
* 9d41e07 Add contact form
* 3f9c2ab Add home pageLine-by-line explanation
- Line 1git st now shows a short, two-letter status for each file: M for modified, ?? for untracked.
- Line 2git lg prints the history as a compact graph, including all branches.
Common Git Config Mistakes
Getting stuck in Vim
git commit
# Vim opens; you can't figure out how to save and quitgit config --global core.editor "code --wait"
git commit
# VS Code opens; save and close the tab to finishIf you're already in Vim, press Esc, type :wq and press Enter to save and quit.
Creating an alias with the "git" prefix
git config --global alias.st "git status" # runs "git git status"git config --global alias.st statusIgnoring line-ending warnings
# "LF will be replaced by CRLF" warnings, and every line shows as changedgit config --global core.autocrlf true # on Windows
# or add a .gitattributes file with: * text=autoGit Config in Real Projects
Configuration in teams
Companies often ask new developers to set pull.rebase, their work email and a commit signing key on their first day. Shared rules, such as line endings, go into .gitattributes and .editorconfig files committed to the repository, so every machine behaves the same way. Personal aliases are a matter of taste, and many developers proudly share theirs.
Git Config FAQ
How do I see which file a Git setting comes from?
Run git config --list --show-origin to list every setting with the file it was read from. For a single setting, use git config --show-origin user.email. This is the quickest way to find out why a repository isn't using the value you expected.
How do I remove a Git config setting?
Use --unset with the same level you set it at, for example git config --global --unset user.signingkey. Aliases are removed the same way: git config --global --unset alias.co. You can also open the file with git config --global --edit and delete the line.
How do I use a different email for work repositories?
Inside the work repository, run git config user.email "sam@company.com" without --global. A local setting overrides the global one for that repository only. If all your work projects live in one folder, an [includeIf "gitdir:~/work/"] section in your global config can load a separate config file for them automatically.
Can a Git alias run a shell command?
Yes. Start the alias value with ! and Git runs it in a shell: git config --global alias.root '!pwd' prints the repository's top folder. Shell aliases run from the top of the repository, not the folder you're in, so keep that in mind for commands that use relative paths.
How do I list all my Git aliases?
Run git config --get-regexp '^alias\.'. Each line shows an alias name followed by the command it expands to. Adding --global limits the list to aliases in your user-level config.
Git Config Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
Complete the command that sets your global editor to VS Code.
git config core.editor "code --wait"
Where are --global settings stored?
Global user.name is "Sam" and the repository's local user.name is "Sam (Work)". What does git config --get user.name print inside that repository?
Complete the command that creates an alias git co for git switch.
git config --global switch
Which setting helps when Windows and Mac users edit the same files?
Git Config Quiz
5 questions to check what you learned.
Which level of Git setting wins when the same key is set in several places?
- Local (the repository)
- System
- Global
- The first one set
What does
git config --list --show-originshow?- Only your aliases
- The remote repositories
- Every setting and the file it comes from
- The commit history
What's the purpose of a Git alias?
- To rename a branch
- To hide a commit
- To share settings with GitHub
- To create your own shorter name for a Git command
What does
--waitdo incode --waitas the editor?- Makes Git wait until you close the file in VS Code
- Delays the commit by a minute
- Opens VS Code in the background
- Saves automatically
Which file lets a team share line-ending rules inside the repository?
- .gitignore
- .gitattributes
- .gitconfig
- README.md