Bird
Raised Fist0
Gitdevops~10 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main difference between git config --global and git config --local?
easy
A. Local config is stored in the user's home directory.
B. Global config applies only to the current project; local config applies to all projects.
C. Global config overrides local config settings.
D. Global config applies to all projects; local config applies only to the current project.

Solution

  1. Step 1: Understand global configuration scope

    Global configuration applies settings to all Git projects on the computer, stored in the user's home directory.
  2. Step 2: Understand local configuration scope

    Local configuration applies only to the current Git project and overrides global settings if both exist.
  3. Final Answer:

    Global config applies to all projects; local config applies only to the current project. -> Option D
  4. Quick Check:

    Global = all projects, Local = current project [OK]
Hint: Global is for all projects, local is project-specific [OK]
Common Mistakes:
  • Confusing which config applies globally or locally
  • Thinking local config is stored in home directory
  • Assuming global config overrides local config
2. Which of the following commands correctly sets the user email only for the current Git project?
easy
A. git config --global user.email "user@example.com"
B. git config --system user.email "user@example.com"
C. git config user.email "user@example.com"
D. git set user.email "user@example.com"

Solution

  1. Step 1: Identify the correct command for local config

    By default, git config without --global or --system sets local config for the current project.
  2. Step 2: Check command syntax

    git config --local is valid but optional; git config user.email "user@example.com" is the simplest correct form.
  3. Final Answer:

    git config user.email "user@example.com" -> Option C
  4. Quick Check:

    Local config uses git config without --global [OK]
Hint: Use git config without --global for local settings [OK]
Common Mistakes:
  • Using --global when wanting local config
  • Using invalid command like git set
  • Assuming --local is mandatory
3. Given these commands run in order inside a Git project:
git config --global user.name "GlobalUser"
git config user.name "LocalUser"
git config user.name

What will be the output of the last command?
medium
A. GlobalUser
B. LocalUser
C. No output (empty)
D. Error: user.name not set

Solution

  1. Step 1: Understand config precedence

    Local config overrides global config when both exist for the same key.
  2. Step 2: Analyze the commands

    First sets global user.name to "GlobalUser", then local user.name to "LocalUser". The last command reads the effective user.name, which is local.
  3. Final Answer:

    LocalUser -> Option B
  4. Quick Check:

    Local overrides global, so output is LocalUser [OK]
Hint: Local config overrides global for same key [OK]
Common Mistakes:
  • Assuming global config always shows
  • Thinking last set value globally is used
  • Confusing output with error
4. You ran git config --local user.name "Alice" but git config user.name still shows "Bob". What is the most likely problem?
medium
A. You are not inside a Git repository directory.
B. You used --local incorrectly; it should be --global.
C. The global config is overriding the local config.
D. The user.name key is misspelled.

Solution

  1. Step 1: Check local config requirements

    Local config applies only inside a Git repository folder. Outside, local config commands fail silently or do not apply.
  2. Step 2: Understand why global shows instead

    If outside a repo, local config is ignored, so global config value "Bob" is shown.
  3. Final Answer:

    You are not inside a Git repository directory. -> Option A
  4. Quick Check:

    Local config needs repo folder [OK]
Hint: Local config works only inside a Git repo folder [OK]
Common Mistakes:
  • Assuming global always overrides local
  • Using wrong option --global instead of --local
  • Misspelling config keys
5. You want to set your Git user email globally but override it with a different email for a specific project. Which sequence of commands achieves this?
hard
A. git config --global user.email "global@example.com"
git config --local user.email "project@example.com" (inside project)
B. git config --local user.email "global@example.com"
git config --global user.email "project@example.com"
C. git config user.email "global@example.com" (inside project)
git config --global user.email "project@example.com"
D. git config --global user.email "project@example.com"
git config user.email "global@example.com" (inside project)

Solution

  1. Step 1: Set global email first

    Use git config --global user.email "global@example.com" to set the default email for all projects.
  2. Step 2: Override locally inside the project

    Inside the project folder, run git config --local user.email "project@example.com" to override the global email only for that project.
  3. Final Answer:

    git config --global user.email "global@example.com" followed by git config --local user.email "project@example.com" inside project -> Option A
  4. Quick Check:

    Global first, then local override inside project [OK]
Hint: Set global first, then local inside project to override [OK]
Common Mistakes:
  • Setting local config before global
  • Using local config outside project folder
  • Confusing which email applies where