Git
Global Config
Data Storage
Version Control
Software Development

Where is the global git config data stored?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

The global Git config file is stored at ~/.gitconfig on macOS and Linux, and at C:\Users\<USERNAME>\.gitconfig on Windows. This file holds user-level settings like your name, email, and preferred editor that apply to every repository you work with on that machine.

Git's Three Configuration Levels

Git reads configuration from three locations, each with a different scope. Settings at a narrower scope override broader ones:

LevelFlagFile LocationScope
System--system/etc/gitconfig (Linux/macOS) or C:\Program Files\Git\etc\gitconfig (Windows)All users on the machine
Global--global~/.gitconfig or ~/.config/git/configAll repos for the current user
Local--local.git/config inside each repoSingle repository only

When Git resolves a setting, it reads all three files and applies them in order: system, then global, then local. A local setting always wins over global, and global always wins over system.

Finding Your Global Config File

The fastest way to locate your global config file is to ask Git directly:

bash
git config --global --list --show-origin

This prints every global setting along with the exact file path it comes from:

 
file:/Users/yourname/.gitconfig  user.name=Your Name
file:/Users/yourname/.gitconfig  user.email=you@example.com
file:/Users/yourname/.gitconfig  core.editor=vim

If you want just the file path without the settings:

bash
# On macOS/Linux
git config --global --list --show-origin | head -1 | cut -d$'\t' -f1

Platform-Specific Locations

macOS and Linux:

bash
1# Primary location (most common)
2~/.gitconfig
3
4# XDG-compliant alternative (Git 1.7.12+)
5~/.config/git/config

Git checks ~/.gitconfig first. If it does not exist, Git falls back to ~/.config/git/config. If both exist, ~/.gitconfig takes priority.

Windows:

 
1# Primary location
2C:\Users\<USERNAME>\.gitconfig
3
4# Git also checks these, in order
5%HOMEDRIVE%%HOMEPATH%\.gitconfig
6%USERPROFILE%\.gitconfig

Git for Windows determines the home directory from the HOME environment variable first, then falls back to HOMEDRIVE + HOMEPATH, then USERPROFILE.

Reading and Writing Global Config

Viewing all global settings

bash
git config --global --list

Setting common values

bash
1# Identity
2git config --global user.name "Your Name"
3git config --global user.email "[email protected]"
4
5# Default editor
6git config --global core.editor "code --wait"
7
8# Default branch name for new repos
9git config --global init.defaultBranch main
10
11# Enable reuse recorded resolution (rerere)
12git config --global rerere.enabled true

Removing a setting

bash
git config --global --unset core.editor

Editing the file directly

bash
git config --global --edit

This opens the global config file in your configured editor (or vi by default).

Inside the Global Config File

The .gitconfig file uses INI-style syntax with sections, keys, and values:

ini
1[user]
2    name = Your Name
3    email = [email protected]
4
5[core]
6    editor = code --wait
7    autocrlf = input
8    pager = delta
9
10[init]
11    defaultBranch = main
12
13[alias]
14    st = status
15    co = checkout
16    br = branch
17    lg = log --oneline --graph --all
18
19[pull]
20    rebase = true
21
22[merge]
23    conflictstyle = diff3
24
25[diff]
26    colorMoved = default

You can edit this file manually with any text editor. Comments start with # or ;.

Conditional Includes

Git 2.13 introduced conditional includes, allowing you to load different config files based on the repository path. This is useful for separating work and personal identities:

ini
1# ~/.gitconfig
2[user]
3    name = Personal Name
4    email = [email protected]
5
6# Override for work repos
7[includeIf "gitdir:~/work/"]
8    path = ~/.gitconfig-work
ini
1# ~/.gitconfig-work
2[user]
3    name = Work Name
4    email = [email protected]

Any repository cloned under ~/work/ automatically picks up the work email without manual per-repo configuration.

Debugging Configuration Precedence

When a setting behaves unexpectedly, check where Git is reading it from:

bash
1# Show where a specific setting comes from
2git config --show-origin user.email
3
4# Show all settings with their origin files
5git config --list --show-origin --show-scope

Example output:

 
system  file:/etc/gitconfig             credential.helper=osxkeychain
global  file:/Users/you/.gitconfig      user.name=Your Name
local   file:.git/config                user.email=project@example.com

The --show-scope flag (Git 2.26+) adds the level label, making it clear which file is winning.

Backing Up and Syncing Config Across Machines

Many developers version-control their dotfiles, including .gitconfig. A common pattern:

bash
1# Create a dotfiles repo
2mkdir ~/dotfiles && cd ~/dotfiles
3git init
4
5# Symlink your gitconfig
6ln -s ~/dotfiles/.gitconfig ~/.gitconfig
7
8# Commit and push
9git add .gitconfig
10git commit -m "Add git config"
11git push origin main

On a new machine, clone the repo and recreate the symlinks. Tools like GNU Stow or chezmoi automate this process.

Common Pitfalls

Editing the wrong file. On systems with both ~/.gitconfig and ~/.config/git/config, manual edits to the XDG file are ignored if ~/.gitconfig exists. Always use git config --global --edit to ensure you are editing the right file.

Forgetting to set identity before the first commit. Git refuses to commit without user.name and user.email. Set these in global config immediately after installing Git to avoid the error on every new repository.

Using global settings that should be local. Settings like core.autocrlf or core.eol may need different values per project (especially in mixed Windows/macOS teams). Set these at the local level rather than global to avoid cross-project conflicts.

Conditional includes not matching. The gitdir pattern in includeIf must end with / to match directories correctly. Without the trailing slash, the condition may silently fail to match.

SSH key confusion with multiple accounts. Global config sets one user.email, but if you push to repos owned by different GitHub accounts, you need per-repo local config or SSH config with Host aliases to route to the correct key.

Summary

The global Git config lives at ~/.gitconfig (or ~/.config/git/config on XDG-compliant setups) and holds settings that apply across all repositories for your user account. Use git config --global commands to read and write settings, --show-origin to debug where values come from, and conditional includes to manage multiple identities. The global level sits between system-wide and per-repository config in Git's precedence chain, making it the right place for personal defaults like your name, email, editor, and aliases.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.