What this error means
Git failed to parse a config file. You’ll see messages like:
- fatal: bad config file at: /path/to/.git/config: line 12
- error: malformed config file in: ~/.gitconfig
The fix is to identify the broken file and correct its syntax or encoding.
Where Git reads config
- Local (repo): .git/config
- Global (user): ~/.gitconfig (Windows: %USERPROFILE%.gitconfig)
- System: $(git --exec-path)/../etc/gitconfig or platform-specific etc/gitconfig
Tip: Git merges these; one bad file breaks all Git commands.
Quickstart: fix in 60 seconds
- Note the file and line number from the error.
- Back up the file.
- Open and fix obvious syntax: section headers, quotes, or conflict markers.
- Save as UTF-8 without BOM; ensure Unix/Windows line endings are consistent.
- Validate by listing config.
Minimal commands:
# 1) Back up
cp .git/config .git/config.bak 2>/dev/null || true
cp ~/.gitconfig ~/.gitconfig.bak 2>/dev/null || true
# 2) Try to list while bypassing other scopes (helps isolate)
GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null git config --file .git/config --list --show-origin || true
GIT_CONFIG_SYSTEM=/dev/null git config --global --list --show-origin || true
# 3) Validate once fixed
git config --list --show-origin
If Git refuses to run due to a broken global config, temporarily bypass it:
GIT_CONFIG_GLOBAL=/dev/null git status
Minimal working example (.git/config)
If your local config is badly broken, replace it with a minimal, valid file and re-add settings.
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
name = Jane Doe
email = [email protected]
[remote "origin"]
url = [email protected]:org/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Then validate:
git config --list --show-origin
Common causes and fixes
- Missing or malformed section headers
- Symptom: lines outside [section] blocks.
- Fix: ensure settings live under headers like [core], [user], [remote "origin"].
Bad:
user.name = Jane
user.email = [email protected]
Good:
[user]
name = Jane
email = [email protected]
- Unbalanced quotes/brackets in section names
- Symptom: [remote "origin] or [remote origin"]
- Fix: use paired quotes around the name.
Good:
[remote "origin"]
url = [email protected]:org/repo.git
- Bad include/includeIf lines
- Symptom: include.path without a value or malformed condition.
- Fix: quote the condition and provide a valid path.
Good:
[include]
path = ~/.gitconfig-common
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
- Merge conflict markers accidentally committed to config
- Symptom: lines starting with <<<<<<<, =======, >>>>>>>.
- Fix: remove markers and keep the intended settings.
- Encoding issues (BOM, UTF-16)
- Symptom: saved as UTF-16/UTF-8 with BOM; Git can’t parse.
- Fix: save as UTF-8 without BOM. On Unix-like systems:
# Strip UTF-8 BOM (GNU sed)
sed -i '1s/^\xEF\xBB\xBF//' ~/.gitconfig
# Or rewrite as UTF-8 without BOM via iconv
iconv -f utf-8 -t utf-8 ~/.gitconfig > ~/.gitconfig.nobom && mv ~/.gitconfig.nobom ~/.gitconfig
- Stray characters or tabs vs. spaces
- Git accepts tabs/spaces, but stray non-printable characters can break parsing. Remove any odd characters.
Step-by-step repair workflow
- Identify the failing file
- Read Git’s error; it usually names the file and line.
- Back up
cp /path/to/file /path/to/file.bak
- Fix syntax in an editor
- Ensure every key is key = value under a valid [section].
- Quote names in subsection headers: [remote "name"].
- Remove conflict markers.
- Correct include/includeIf lines.
- Save as UTF-8 without BOM.
- Validate
git config --list --show-origin
If still failing, narrow scope:
GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null git config --file .git/config --list
GIT_CONFIG_NOSYSTEM=1 git config --global --list
Recreate a fresh local config
If .git/config is beyond repair:
mv .git/config .git/config.broken
# Reinitialize to regenerate minimal structure
git init
# Re-add remote and essentials
git remote add origin [email protected]:org/repo.git
git config user.name "Your Name"
git config user.email "[email protected]"
Pitfalls to avoid
- Editing with tools that save UTF-16 or add BOMs.
- Copy-pasting from rich text; it may insert smart quotes or non-breaking spaces.
- Typos in includeIf conditions (must be like "gitdir:PATH/").
- Comment syntax: use # or ; at line start; inline comments after values can be risky.
- Mixing multiple conflicting definitions; last one wins but can be confusing.
Performance notes
- Many nested include files slow startup slightly; consolidate where possible.
- Keep config small and relevant to your workflow.
- Prefer includes for rarely used settings to avoid parsing large files on every command.
FAQ
Q: Where are my config files? A: Local: .git/config in the repo. Global: ~/.gitconfig (Windows: %USERPROFILE%.gitconfig). System: platform gitconfig in etc.
Q: Git won’t run because my global file is broken. How can I work? A: Temporarily bypass it: GIT_CONFIG_GLOBAL=/dev/null git <cmd>. Then fix ~/.gitconfig.
Q: Can I delete .git/config? A: Yes, but back it up first. Run git init to recreate basics, then re-add remotes and settings.
Q: How do I validate after fixing? A: Run git config --list --show-origin. It should print all settings without errors.
Q: Do CRLF line endings matter? A: Git can parse CRLF or LF, but inconsistent encoding (UTF-16/BOM) breaks parsing; prefer UTF-8 without BOM.