This error occurs when Git cannot access its configuration file due to missing files, incorrect permissions, or misconfigured environment variables. The fix depends on which config level is affected.
When you run a Git command, Git reads configuration settings from up to three levels of configuration files: system-level (`/etc/gitconfig`), global user-level (`~/.gitconfig` or `~/.config/git/config`), and local repository-level (`.git/config`). The "fatal: unable to read config file" error occurs when Git cannot access one of these files. This error typically appears in several scenarios: the configuration file doesn't exist and Git cannot create it, file permissions prevent Git from reading the file, environment variables point to invalid paths (especially on Windows), or a symbolic link points to a non-existent target. On Windows systems, this error is particularly common when the HOME environment variable is not set correctly, or when Git is configured to look for configuration files on a network drive that's currently inaccessible. The error message usually includes the path Git was trying to access, which helps identify which configuration level is affected.
The error message includes the path Git tried to access. Common locations are:
System level: /etc/gitconfig (Linux/macOS) or C:\ProgramData\Git\config (Windows)
Global level: ~/.gitconfig or ~/.config/git/config
Local level: .git/config (inside repository)
To see all config files and their locations:
git config --list --show-originThis shows every configuration setting along with its source file.
Verify the file exists and check its permissions:
# For global config
ls -la ~/.gitconfig
# For local config (run from repo root)
ls -la .git/configIf the file exists but has wrong permissions, fix them:
# Make config file readable and writable by owner
chmod 644 ~/.gitconfig
# For local repository config
chmod 644 .git/configIf the file is owned by root, change ownership:
sudo chown $USER:$USER ~/.gitconfigIf the config file doesn't exist, Git can create it when you set a configuration value:
# Create global config with your identity
git config --global user.name "Your Name"
git config --global user.email "[email protected]"For local repository config:
# Initialize or reinitialize the repository
git initThis creates the .git directory and config file if they don't exist.
On Windows, Git uses the HOME environment variable to locate ~/.gitconfig. If this variable is missing or incorrect:
Temporary fix (current session):
SET HOME=%USERPROFILE%Permanent fix:
1. Open System Properties > Advanced > Environment Variables
2. Under User variables, click "New"
3. Variable name: HOME
4. Variable value: %USERPROFILE% or your actual home path (e.g., C:\Users\YourUsername)
5. Click OK and restart your terminal
PowerShell permanent fix:
[Environment]::SetEnvironmentVariable("HOME", $env:USERPROFILE, "User")If ~/.gitconfig is a symbolic link, verify its target exists:
# Check if it's a symlink and where it points
ls -la ~/.gitconfig
readlink ~/.gitconfigIf the target doesn't exist, either:
Option A: Create the target directory and file:
# If symlink points to ~/dotfiles/.gitconfig
mkdir -p ~/dotfiles
touch ~/dotfiles/.gitconfigOption B: Remove the broken symlink and create a regular file:
rm ~/.gitconfig
git config --global user.name "Your Name"If Git is configured to look for config on a network drive that's not always available:
Check your Git configuration path:
git config --list --show-origin 2>&1 | head -5If you see a network path (like H:\ or \\server\share):
1. Ensure you're connected to the network/VPN
2. Or redirect HOME to a local path:
SET HOME=C:\Users\%USERNAME%Check Git installation config:
Look at <git-install-path>/etc/profile to see how HOME is being set. You may need to modify this or set HOME before Git reads it.
If you see "Permission denied" or "File exists" along with the config error, there may be a stale lock file:
# Check for lock files
ls -la ~/.gitconfig.lock
ls -la .git/config.lockIf lock files exist, delete them:
rm -f ~/.gitconfig.lock
rm -f .git/config.lockLock files are created during config writes and should be automatically removed. Their presence usually indicates a previous Git operation was interrupted.
After applying fixes, verify Git can read its configuration:
# List all configuration
git config --list
# Test a specific config level
git config --global --list
git config --local --list
# Show config files and their locations
git config --list --show-originIf no errors appear and you see your configuration values, the issue is resolved.
### Configuration File Hierarchy
Git reads configuration in this order, with later values overriding earlier ones:
1. System (--system): /etc/gitconfig - applies to all users
2. Global (--global): ~/.gitconfig or ~/.config/git/config - your personal settings
3. Local (--local): .git/config - repository-specific settings
4. Worktree (--worktree): .git/config.worktree - worktree-specific (rare)
### XDG Base Directory Support
Git 2.0+ supports XDG Base Directory Specification. If ~/.gitconfig doesn't exist, Git also checks ~/.config/git/config. You can use either location.
### Windows Path Expansion Issues
The error fatal: unable to read config file '%HOMEDRIVE%%HOMEPATH%/.gitconfig' indicates environment variables aren't being expanded. This typically happens when:
- Running Git from a context where environment variables aren't set (scheduled tasks, services)
- The Git installation has incorrect path configuration
- Running "as different user" where the target user's environment isn't loaded
### Git for Windows Installation Check
If issues persist on Windows, verify your Git installation:
# Check Git location
where git
# Check Git version
git --version
# Reinstall if needed - use Git for Windows installer with default settings### Multiple Git Installations
Having multiple Git installations (Git for Windows, WSL Git, Cygwin Git) can cause conflicts. Ensure your PATH points to the correct Git installation and that HOME is set appropriately for that environment.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git