🔀 Fix includeIf Conditional Config Not Matching on Windows
A conditional [includeIf "gitdir:..."] block in .gitconfig matches repository paths using case-sensitive, forward-slash path comparison internally, even on Windows — a path written with backslashes, or with a drive letter in a different case than the actual working directory Git reports, silently fails to match, and the included config (often a different user name/email for work repos) never applies, with no warning that the conditional block was simply skipped.
🔎 The Problem
# .gitconfig
[includeIf "gitdir:C:\Users\ercan\work\"]
path = .gitconfig-work
# Backslashes used instead of forward slashes, and drive letter
# case may differ from what `git rev-parse --show-toplevel` reports
$ git config user.email
# returns the personal default, not the expected work override
✅ Fix: Match the Path Format Git Actually Compares Against
- Rewrite the
gitdir:pattern using forward slashes even on Windows (gitdir:C:/Users/ercan/work/), since that’s the normalized form Git compares the repository path against internally regardless of platform. - Run
git rev-parse --show-toplevelinside the actual work repository and copy the drive letter casing it reports exactly, rather than typing the path from memory or from Explorer’s address bar. - Confirm the fix with
git config --show-origin user.emailrun from inside the work repo, which shows exactly which config file actually supplied the active value — the global default or the conditional include.
IncludeIf matches the path Git actually sees, not the path you typed — on Windows those aren’t automatically the same string.





