Global vs local configuration in Git - Performance Comparison
Start learning this pattern below
Jump into concepts and practice - no test required
When using git, configuration settings can be global or local. Understanding how git reads these settings helps us see how time grows when many configs exist.
We want to know: How does git find the right setting as configurations increase?
Analyze the time complexity of git reading configuration values.
# Show global config
$ git config --global user.name
# Show local config
$ git config --local user.name
# Set local config
$ git config --local user.email "user@example.com"
# Read config (git checks local then global)
$ git config user.name
This code shows how git reads and sets user info in global and local configs.
Git looks for config values by checking files in order.
- Primary operation: Reading config files one by one.
- How many times: Once per config file until value found or all checked.
As the number of config files grows, git checks each file in order.
| Input Size (number of config files) | Approx. Operations (file checks) |
|---|---|
| 2 | Up to 2 file reads |
| 5 | Up to 5 file reads |
| 10 | Up to 10 file reads |
Pattern observation: The more config files, the more files git checks one by one.
Time Complexity: O(n)
This means git's time to find a config grows linearly with the number of config files it checks.
[X] Wrong: "Git reads all config files instantly no matter how many there are."
[OK] Correct: Git reads files one by one until it finds the setting, so more files mean more checks and more time.
Understanding how git reads configs helps you think about how tools handle layered settings. This skill shows you can analyze how processes grow with input size.
"What if git cached config values after first read? How would the time complexity change?"
Practice
git config --global and git config --local?Solution
Step 1: Understand global configuration scope
Global configuration applies settings to all Git projects on the computer, stored in the user's home directory.Step 2: Understand local configuration scope
Local configuration applies only to the current Git project and overrides global settings if both exist.Final Answer:
Global config applies to all projects; local config applies only to the current project. -> Option DQuick Check:
Global = all projects, Local = current project [OK]
- Confusing which config applies globally or locally
- Thinking local config is stored in home directory
- Assuming global config overrides local config
Solution
Step 1: Identify the correct command for local config
By default,git configwithout--globalor--systemsets local config for the current project.Step 2: Check command syntax
git config --localis valid but optional;git config user.email "user@example.com"is the simplest correct form.Final Answer:
git config user.email "user@example.com" -> Option CQuick Check:
Local config usesgit configwithout--global[OK]
- Using --global when wanting local config
- Using invalid command like git set
- Assuming --local is mandatory
git config --global user.name "GlobalUser" git config user.name "LocalUser" git config user.name
What will be the output of the last command?
Solution
Step 1: Understand config precedence
Local config overrides global config when both exist for the same key.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.Final Answer:
LocalUser -> Option BQuick Check:
Local overrides global, so output is LocalUser [OK]
- Assuming global config always shows
- Thinking last set value globally is used
- Confusing output with error
git config --local user.name "Alice" but git config user.name still shows "Bob". What is the most likely problem?Solution
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.Step 2: Understand why global shows instead
If outside a repo, local config is ignored, so global config value "Bob" is shown.Final Answer:
You are not inside a Git repository directory. -> Option AQuick Check:
Local config needs repo folder [OK]
- Assuming global always overrides local
- Using wrong option --global instead of --local
- Misspelling config keys
Solution
Step 1: Set global email first
Usegit config --global user.email "global@example.com"to set the default email for all projects.Step 2: Override locally inside the project
Inside the project folder, rungit config --local user.email "project@example.com"to override the global email only for that project.Final Answer:
git config --global user.email "global@example.com" followed by git config --local user.email "project@example.com" inside project -> Option AQuick Check:
Global first, then local override inside project [OK]
- Setting local config before global
- Using local config outside project folder
- Confusing which email applies where
