How to fix fatal: bad config line in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 189 views

This error occurs when Git encounters a malformed or corrupted configuration file. The config file has invalid syntax, missing sections, special characters, or invisible formatting issues that prevent Git from parsing it.

Quick fix

Fixes fatal: bad config line

fatal: bad config line 3 in file /home/user/.gitconfig
  1. Identify the problematic file and line
  2. Check for invisible characters
  3. Fix smart quotes from text editors
  4. Verify proper INI section format
git — error
fatal: bad config line 3 in file /home/user/.gitconfig
fatal: bad config line

What this error means

When you see `fatal: bad config line X in file /path/to/.gitconfig`, Git is telling you that it found invalid syntax on a specific line in one of your configuration files. Git configuration files use an INI-like format with sections in square brackets followed by key-value pairs. The error typically occurs because the config file has been corrupted, edited incorrectly, or contains characters that Git cannot parse. Common culprits include incomplete section headers (missing closing brackets), incorrect indentation, special quote characters inserted by text editors like Mac TextEdit, lone backslashes, or invisible characters like NULL bytes or Windows carriage returns. Git reads configuration from three locations: system-wide (`/etc/gitconfig`), user-global (`~/.gitconfig` or `~/.config/git/config`), and repository-local (`.git/config`). The error message tells you exactly which file and line number contains the problem.

Typical symptoms

  • Any Git command fails with 'fatal: bad config line X in file...'
  • Error appears suddenly after editing .gitconfig or cloning a repository
  • Git commands worked fine before but now all fail with config errors
  • Error persists across all Git commands (status, log, clone, pull, etc.)
  • The error message points to a specific file path and line number

Common causes

  1. Corrupted config file with invisible characters, NULL bytes, or spaces/tabs only
  2. Text editor inserted 'smart quotes' (curly quotes) instead of standard ASCII quotes
  3. Missing closing bracket on a section header like [core
  4. Raw Git command written directly in config file instead of proper INI format
  5. Unescaped backslash character in a path (Windows paths need \\ or forward slashes)
  6. Windows line endings (CRLF) causing parsing issues on some systems

How to fix "fatal: bad config line"

1Identify the problematic file and line

The error message tells you exactly where the problem is. Note the file path and line number:

bash
fatal: bad config line 3 in file /home/user/.gitconfig

In this example, line 3 of ~/.gitconfig has the issue. Open the file to inspect:

bash
# View the file with line numbers
cat -n ~/.gitconfig

# Or use your preferred editor
nano ~/.gitconfig
code ~/.gitconfig
2Check for invisible characters

Often the problem is invisible characters that look fine but break parsing. Use cat -A to reveal hidden characters:

bash
cat -A ~/.gitconfig

Look for:
- ^M at line endings (Windows carriage returns)
- ^@ or M-^@ (NULL characters)
- Extra whitespace or tabs where there should not be any
- Non-ASCII characters in section names or keys

If the file appears empty but has content, or shows strange characters, that is likely the problem.

3Fix smart quotes from text editors

If you edited the config file with Mac TextEdit or certain other editors, they may have converted standard double quotes to curly 'smart' quotes:

Bad (curly quotes):

bash
[user]
    email = "user@example.com"

Good (straight quotes):

bash
[user]
    email = "user@example.com"

Open the file in a plain text editor (VS Code, nano, vim) and replace any curly quotes with standard ASCII quotes. In VS Code, use Find and Replace with:
- Find: [“”] (regex mode)
- Replace: "

4Verify proper INI section format

Git config files must follow INI format with sections and key-value pairs. A common mistake is writing Git commands directly into the file:

Wrong:

bash
git config core.editor "nano"

Correct:

bash
[core]
    editor = nano

Ensure every section header has both opening [ and closing ] brackets, and values are on their own lines with key = value format.

5Escape backslashes in Windows paths

If you have Windows paths in your config, backslashes need to be escaped or replaced:

Wrong:

bash
[core]
    editor = C:\Program Files\Notepad++\notepad++.exe

Correct (escaped backslashes):

bash
[core]
    editor = C:\\Program Files\\Notepad++\\notepad++.exe

Also correct (forward slashes):

bash
[core]
    editor = C:/Program Files/Notepad++/notepad++.exe

Or use quotes with single backslashes:

bash
[core]
    editor = "C:\\Program Files\\Notepad++\\notepad++.exe"
6Use divide-and-conquer to find the problem

If you cannot spot the issue visually, comment out sections until Git works:

bash
# Comment out all lines with # and test
git config --global --list

# If that works, uncomment sections one at a time
# to isolate which section causes the error

Alternatively, rename the config file and recreate it:

bash
mv ~/.gitconfig ~/.gitconfig.backup
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Then compare the new working config with your backup to find differences.

7Fix or recreate the config file

If the file is severely corrupted, the fastest fix is to recreate it:

bash
# Backup the old config
mv ~/.gitconfig ~/.gitconfig.old

# Create a fresh config with essential settings
git config --global user.name "Your Name"
git config --global user.email "your@example.com"
git config --global core.editor "code --wait"

For repository-local config issues (.git/config):

bash
# If no commits exist, reinitialize
rm -rf .git
git init

# If commits exist, copy config from another working repo
# or re-clone from remote
8Verify the fix

After making changes, verify Git can read the config:

bash
# List all config values (should work without errors)
git config --global --list

# Check repository-specific config
git config --local --list

# Run a simple Git command
git status

If these commands run without the 'bad config line' error, the issue is resolved.

Advanced notes

Multiple config file locations: Git reads configuration from multiple files in order of precedence. If you fix one file but still get errors, check all three locations:

1. System: /etc/gitconfig (affects all users)
2. Global: ~/.gitconfig or ~/.config/git/config (user-specific)
3. Local: .git/config (repository-specific)

Symlink issues on Windows/Cygwin: If you use Cygwin with Windows Git, symlinks can cause problems. Cygwin creates symlinks that native Windows Git cannot read properly. The symlink file may contain binary data instead of the expected text content. Consider using hard links or copying the file instead.

Config includes: Git supports including other config files with [include] directives. If you use includes, the error might be in an included file rather than the main config:

ini
[include]
    path = ~/.gitconfig.local

Check included files as well when troubleshooting.

SSH vs Git config: Some users mistakenly put SSH configuration into .gitconfig. SSH config belongs in ~/.ssh/config, not in Git's configuration files.

Frequently asked questions

What does "fatal: bad config line" mean?
gitconfig, Git is telling you that it found invalid syntax on a specific line in one of your configuration files. Git configuration files use an INI-like format with sections in square brackets followed by key-value pairs. The error typically occurs because the config file has been corrupted, edited incorrectly, or contains characters that Git cannot parse.
How do I fix "fatal: bad config line"?
This error occurs when Git encounters a malformed or corrupted configuration file. The config file has invalid syntax, missing sections, special characters, or invisible formatting issues that prevent Git from parsing it.
What causes "fatal: bad config line"?
Corrupted config file with invisible characters, NULL bytes, or spaces/tabs only Text editor inserted 'smart quotes' (curly quotes) instead of standard ASCII quotes Missing closing bracket on a section header like [core
Is the "fatal: bad config line" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading