Conditional Git Config With includeIf
Switch user identity or settings based on which directory a repo is in.
Use includeIf."gitdir:~/work/".path to load a work config only inside that tree.
01Command
Command
$ git config --global includeIf."gitdir:~/work/".path ~/.gitconfig-work02What it does
Conditional includes let one machine carry several identities, automatically applying the right name, email and signing key depending on where the repository lives. This prevents committing with the wrong identity, a problem purely handled by configuration from the shell.
03Risk
!Warning: Paths must end with a trailing slash for gitdir patterns; test with git config --list --show-origin.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- git-git-config documentationEvidence: Documents git config, including conditional includes via includeIf.
Last verified: 2026-10-13 · Category: Developer