0
0
Gitdevops~10 mins

Global vs local configuration in Git - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Global vs local configuration
Start
Check config scope
Use ~/.gitconfig
Apply global settings
Use .git/config
Apply local settings
Local overrides global
End
Git checks if configuration is global or local, applies global settings first, then local settings override global ones if present.
Execution Sample
Git
git config --global user.name "Alice"
git config user.email "alice@example.com"
git config user.name
Set global user name, set local user email, then read user name (local or global).
Process Table
StepCommandConfig File UsedActionResult / Output
1git config --global user.name "Alice"~/.gitconfigSet user.name globallyuser.name = Alice saved globally
2git config user.email "alice@example.com"./.git/configSet user.email locallyuser.email = alice@example.com saved locally
3git config user.nameCheck local then globalRead user.nameAlice (from global)
4git config user.emailCheck local then globalRead user.emailalice@example.com (from local)
💡 Commands complete; local config overrides global when both exist.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
user.nameundefinedAlice (global)Alice (global)Alice (global)Alice (global)
user.emailundefinedundefinedalice@example.com (local)alice@example.com (local)alice@example.com (local)
Key Moments - 2 Insights
Why does 'git config user.name' show the global value even though we set a local email?
Because user.name was only set globally (step 1), and local config does not override it, so git reads global value (step 3).
What happens if both global and local have the same setting?
Local config overrides global config, so the local value is used (shown in step 4 for user.email).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of user.name after step 2?
Aalice@example.com
BAlice (global)
Cundefined
DAlice (local)
💡 Hint
Check variable_tracker column 'After Step 2' for user.name value.
At which step does git read the local configuration for user.email?
AStep 4
BStep 2
CStep 3
DStep 1
💡 Hint
Look at execution_table rows for user.email read commands.
If we set user.name locally after step 2, how would step 3 output change?
AIt would still show the global user.name
BIt would show undefined
CIt would show the local user.name
DIt would cause an error
💡 Hint
Local config overrides global config as shown in key moments.
Concept Snapshot
Git config has two main scopes:
- Global: applies to all repos for the user (~/.gitconfig)
- Local: applies only to current repo (.git/config)
Local settings override global ones if both exist.
Use --global flag to set global config.
Without --global, config is local by default.
Full Transcript
This visual trace shows how git configuration works with global and local scopes. First, the global user.name is set to Alice. Then, a local user.email is set for the current repository. When git reads user.name, it finds only the global value, so it returns Alice. When git reads user.email, it finds the local value and returns alice@example.com. Local configuration overrides global when both exist. This helps users customize settings per repository or globally for all repositories.