Credential storage options in Git - Time & Space Complexity
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?