What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Git’s includeIf lets you load settings from another config file only when a condition matches—for example, using a work email in repositories under ~/work/ and a personal email elsewhere. Put an [includeIf "condition"] section in a Git config file, set its path, then verify the effective value from a repository with git config --show-origin.
What includeIf does
includeIf conditionally includes directives from another Git configuration file. It is a Git configuration feature, not a shell conditional. If the condition is true, Git reads the included file at the point where the include appears in the configuration stream; if it is false, Git may ignore that section. See the Git configuration manual.
The basic form in your global ~/.gitconfig is:
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
The condition goes in quotes after includeIf. The path names the file to load. A path beginning with ~/ expands from your home directory; a relative path is resolved from the config file containing the include directive.
Choose a condition that matches how you organize repositories
Git offers conditions based on the repository’s Git directory, worktree location, current branch, or remote URL. The right one depends on which property should determine the setting.
Recommended Free Tools
#1 Best Overall
| Condition | What it matches | Use it when |
|---|---|---|
gitdir: |
The location of the repository’s .git directory, using Git glob rules. |
Settings should follow where repositories are stored, such as separate work and personal folders. |
gitdir/i: |
The .git directory location, matched without case sensitivity. |
Path capitalization can vary, especially on a case-insensitive file system. |
worktree: |
The worktree location. | Settings should follow the checkout location rather than the Git directory. |
worktree/i: |
The worktree location, matched without case sensitivity. | The checkout path may vary in capitalization. |
onbranch: |
The currently checked-out branch name. | Settings should apply to a branch or branch namespace, not to a repository directory. |
hasconfig:remote.*.url: |
Whether at least one remote URL matches the supplied glob. | Settings should follow a remote host or URL pattern. |
Match repositories by directory with gitdir:
A pattern ending in / gets recursive ** behavior. Thus, gitdir:~/work/ can match Git directories below ~/work/, not just a directory named exactly work. Git documents path-matching details, including that outside $GIT_DIR both symlink and real-path forms can match, while .. is treated literally rather than normalized. Avoid writing a pattern that assumes Git will resolve .. for you.
Use gitdir/i: instead if directory capitalization might differ. Both conditions match the Git directory, not necessarily the visible checkout path.
Match by worktree, branch, or remote
Use worktree: when the checkout’s location is the deciding factor, including cases where that is more useful than the location of the .git directory. Add /i to make a worktree pattern case-insensitive.
onbranch: checks the checked-out branch. A trailing slash matches a branch namespace recursively, so onbranch:topic/ covers names such as topic/one. This selects by branch, not by repository directory.
Rank #2
hasconfig:remote.*.url: checks whether a remote URL matches a Git glob. Git performs a look-ahead scan for this condition. A file included through a hasconfig condition cannot define remote URLs itself; that restriction prevents the included file from creating the very remote match used to select it.
Set different work and personal commit identities
Set your name globally, then include a small identity file for each repository location. For example, add this to ~/.gitconfig:
[user]
name = Your Name
useConfigOnly = true
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personal
Put the work email in ~/.gitconfig-work:
[user]
email = you@company.example
Put the personal email in ~/.gitconfig-personal:
[user]
email = you@example.net
Here, useConfigOnly = true prevents Git from guessing an identity when no configured email is available. The directory patterns must match the actual locations of the repositories’ Git directories. Adjust the paths if your checkouts live elsewhere.
Select settings by remote URL instead
If company repositories are not all stored in one directory, match their remote URLs. These two conditions cover common HTTPS and SSH URL forms for repositories under the company path on GitHub:
[includeIf "hasconfig:remote.*.url:https://github.com/company/**"]
path = ~/.gitconfig-company
[includeIf "hasconfig:remote.*.url:git@github.com:company/**"]
path = ~/.gitconfig-company
Git globbing applies to the URL pattern. The included ~/.gitconfig-company must not define remote URLs, because files selected by hasconfig are not permitted to introduce them.
Apply settings to a branch namespace
For a setting that should apply whenever the current branch is under release/, use:
[includeIf "onbranch:release/"]
path = ~/.gitconfig-release
Place the settings to apply in ~/.gitconfig-release. A branch-based condition follows the checked-out branch; it does not pick a repository based on its path.
Check which configuration Git actually uses
-
List global entries and their source files:
git config --global --list --show-origin. Check that Git sees the config file containing your include directive.Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Recommended: Update Every Outdated Driver on Your PC in One Scan - Free →Recommended: PC Feels Slow? A Free Scan Shows What's Dragging Windows Down →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
From the target repository, inspect the effective email and its origin:
git config --show-origin --get user.email. The reported origin helps identify which file supplied the value. -
Check the repository’s Git directory with
git rev-parse --git-dir, then compare that location with yourgitdir:pattern. Remember that the condition matches the Git directory, not simply the path you expect to see for the checkout. -
If needed, temporarily put a distinctive test value in the included file and check whether it appears. Remove the test value when done.
Why a conditional include may not apply
-
The pattern does not match. Check the Git directory reported by
git rev-parse --git-dirand confirm that your glob covers its location. A trailing slash on agitdir:pattern gives it recursive matching behavior.Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesSpecial offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Best Value
-
The include section is malformed. Confirm that the condition is quoted and the section contains a
pathentry. -
You expected
..to be normalized. Git treats it literally in these path-matching rules; write a pattern for the path Git matches instead. -
The remote condition depends on a remote in its included file. A file selected by
hasconfig:remote.*.url:cannot define remote URLs, so the URL being matched must be found elsewhere in the configuration. -
A later value overrides the included setting. Git reads the included file where the directive appears. A later value can override an earlier single-valued setting; multi-valued variables follow Git’s normal accumulation rules. Use
git config --show-originto locate the effective value.Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Quick Recap
Bestseller No. 1Bestseller No. 4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

