Configuration Locations

What

Git stores configuration parameters across multiple hierarchical levels on your machine. From the most general to the most specific, these locations are:

  1. System: /etc/gitconfig — Applies to all users and all repositories on the machine.
  2. Global: ~/.gitconfig (or ~/.config/git/config) — Applies to all repositories created by your system user.
  3. Local: .git/config — Applies strictly to the single repository where the file resides.
  4. Worktree: .git/config.worktree — Applies to a specific working tree of a project.

How

You specify which level to read or write using command flags. By default, Git reads and writes to the local level:

# Write to the global configuration (applies everywhere)
git config set --global user.name "John Doe"

# Write to the local configuration (applies only in this project folder)
git config set --local user.email "project-specific@email.com"

Why

Git resolves settings using an overriding hierarchy: a more specific configuration level overrides any matching keys in a more general level. For example, if your global name is set to “John Doe”, but you configure a local name of “Work Persona” in a work project, Git will automatically use “Work Persona” for commits in that repository. This provides incredible flexibility to manage distinct credentials (e.g., personal vs. professional GitHub accounts) across different project folders.

Summary

Git resolves config values by checking levels from system down to local, allowing project-specific settings in .git/config to safely override global settings in ~/.gitconfig.