Credential storage options in Git - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to access stored credentials changes as the number of credentials grows in git.
How does git handle looking up credentials when you have many stored?
Analyze the time complexity of this git credential helper usage.
# Store credentials
$ git config --global credential.helper store
# When pushing, git reads credentials from the file
$ git push origin main
# Git reads ~/.git-credentials file line by line to find matching URL
This snippet shows git using the 'store' helper which saves credentials in a plain text file and reads it on demand.
Look for repeated steps git does when accessing credentials.
- Primary operation: Reading the credentials file line by line to find a matching URL.
- How many times: Once per git command needing credentials, scanning up to all stored entries.
As the number of stored credentials grows, git reads more lines to find the right one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Reads about 10 lines |
| 100 | Reads about 100 lines |
| 1000 | Reads about 1000 lines |
Pattern observation: The time to find credentials grows roughly in direct proportion to the number of stored entries.
Time Complexity: O(n)
This means the time to find credentials grows linearly with how many credentials are stored.
[X] Wrong: "Git finds credentials instantly no matter how many are stored."
[OK] Correct: Git reads the file line by line, so more entries mean more reading time.
Understanding how credential lookup scales helps you reason about performance in real tools and shows you can think about efficiency in everyday tasks.
What if git used a database or key-value store instead of a plain file? How would the time complexity change?
Practice
Solution
Step 1: Understand credential helper types
Git offers different helpers:cachestores credentials temporarily in memory,storesaves them permanently in plain text, and platform helpers likeosxkeychainormanager-corestore securely.Step 2: Identify temporary storage helper
Thecachehelper keeps credentials in memory for a short time (default 15 minutes), so you don't have to retype passwords repeatedly during that period.Final Answer:
cache -> Option DQuick Check:
Temporary credential storage = cache [OK]
- Confusing 'store' as temporary storage
- Thinking 'osxkeychain' is temporary
- Assuming 'manager-core' caches credentials
Solution
Step 1: Recall command syntax for setting credential helper
The command to set a credential helper globally isgit config --global credential.helper <helper-name>.Step 2: Identify helper for permanent plain text storage
Thestorehelper saves credentials permanently in plain text on disk, so the correct command isgit config --global credential.helper store.Final Answer:
git config --global credential.helper store -> Option AQuick Check:
Permanent plain text storage uses 'store' helper [OK]
- Using 'cache' instead of 'store' for permanent saving
- Confusing platform helpers with plain text storage
- Missing the --global flag
git config --get credential.helper after running git config --global credential.helper cache?Solution
Step 1: Understand the effect of setting credential helper globally
Runninggit config --global credential.helper cachesets the credential helper tocachein the global Git config.Step 2: Check what
This command reads the current credential helper setting, which will begit config --get credential.helperreturnscacheafter the previous command.Final Answer:
cache -> Option BQuick Check:
Get helper after setting cache = cache [OK]
- Expecting output to be 'store' or platform helper
- Confusing local and global config scopes
- Assuming no output if helper is set
git config --global credential.helper store, but your password is still asked every time. What is the most likely cause?Solution
Step 1: Understand how 'store' helper works
The 'store' helper saves credentials in a plain text file (usually ~/.git-credentials). If this file is missing or unreadable, Git cannot use stored credentials.Step 2: Identify why password prompts continue
If the credentials file is missing or has wrong permissions, Git will ask for the password every time despite the helper setting.Final Answer:
The stored credentials file is missing or unreadable -> Option CQuick Check:
Missing credentials file causes repeated password prompts [OK]
- Thinking cache overrides store automatically
- Believing Git needs restart after config change
- Assuming platform helpers are mandatory
Solution
Step 1: Identify platform-specific secure helpers
On Windows, the recommended secure credential helper ismanager-core, which integrates with Windows Credential Manager.Step 2: Compare with other helpers
cacheis temporary,storesaves plain text, andosxkeychainis for macOS, so they are not suitable for Windows secure storage.Final Answer:
manager-core -> Option AQuick Check:
Windows secure storage uses 'manager-core' helper [OK]
- Choosing 'store' which is insecure
- Using 'osxkeychain' on Windows
- Expecting 'cache' to be secure and permanent
