The Hook (The "Byte-Sized" Intro)
Git doesn't have one config — it has three layers that stack on top of each other. System covers every user on the machine. Global covers everything you do. Local overrides both for one specific repo. Understanding this cascade explains why your name shows up wrong in certain repos and how to fix it in seconds.
📖 What are Config Levels?
Git configuration is stored at three levels: system, global, and local. Each level overrides the one above it — local wins over global, global wins over system.
Conceptual Clarity
The three levels:
| Level | Scope | File Location | Flag |
|---|---|---|---|
| System | All users on the machine | /etc/gitconfig | --system |
| Global | Current user, all repos | ~/.gitconfig | --global |
| Local | Current repository only | .git/config | --local |
Override order (highest priority wins):
Local → overrides → Global → overrides → System
Why this matters: You can set your personal email globally but override it with a work email in company repos using local config.
Real-Life Analogy
Config levels are like dress codes. The building has a general rule (system), your floor has its own rule (global), and your meeting room can override both (local). The most specific rule always wins.
Visual Architecture
Why It Matters
- Flexibility: Different settings for different repos (work vs personal).
- Debugging: When config behaves unexpectedly, check all three levels.
- Organization: Global for preferences, local for project-specific overrides.
- Team consistency: Local config can enforce project standards.
Code
# ─── View config at each level ───
git config --system --list # System config
git config --global --list # Global config
git config --local --list # Local config (in a repo)
# ─── See where a value comes from ───
git config --show-origin user.email
# file:/home/user/.gitconfig jane@personal.com
# ─── Set at different levels ───
git config --global user.name "Jane Doe"
git config --local user.email "jane@company.com"
# ─── Override for a work repo ───
cd ~/work/project
git config --local user.email "jane@company.com"
# This repo now uses the work email
# ─── View all effective config ───
git config --list --show-origin
# Shows every setting and which file it comes fromKey Takeaways
- Git has 3 config levels: system, global, local — local wins.
- Use
--show-originto debug where a setting comes from. - Set personal defaults globally; override per-repo with local config.
git config --list --show-originshows the full picture.
Interview Prep
-
Q: What are the three levels of Git configuration? A: System (
/etc/gitconfig, all users), Global (~/.gitconfig, current user), and Local (.git/config, current repo). Local overrides Global, which overrides System. -
Q: How do you use different emails for different repos? A: Set your personal email with
git config --global user.email "personal@email.com"and override it in work repos withgit config --local user.email "work@email.com". -
Q: How do you debug where a Git config value comes from? A:
git config --show-origin <key>shows the file that set the value.git config --list --show-originshows all settings with their source files.