Reputation: 13558
Git version: 2.13.0.windows.1
OS: Windows 7
CLI: Git bash
.gitconfig
[user]
name = Gyandeep Singh
email = [email protected]
[push]
default = current
[core]
autocrlf = input
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
path = .gitconfig-work
.gitconfig-work
[user]
name = Gyandeep Singh
email = [email protected]
What happened: open CLI on a folder (example test) inside corporate folder and then run git config user.email
the output is [email protected]
.
Expected: Outcome should be [email protected]
.
Am I doing something wrong or my expectation is not correct? I did follow the git docs.
You have to run git config --show-origin --get user.email
on a git initialized directory. If its not git initialized then the includeIf gitdir
functionality will not work.
Its strange but true. I wish it still worked.
Upvotes: 69
Views: 18527
Reputation: 353
I mapped a directory to a drive on a windows machine with subst D: <mapped directory>
. If you want to know the path of your repository you can use this command in the repository context:
git rev-parse --show-toplevel
The output was something like this:
<mapped directory>/<name of repository>
So I changed it to:
[includeIf "gitdir:<mapped directory>/"]
path = .gitconfig-work
Now it works for me.
Upvotes: 2
Reputation: 1088
The OP concludes that includeIf functionality does not work in normal non-git directories.
This is provably incorrect for at least the configuration item core.sshCommand. If a conditionally included .gitconfig has a core.sshCommand configured, it is used in git clone operations in normal non-git directories.
It seems that the part that doesn't work properly is the display of conditionally included configuration. Which is quite problematic and interferes with tracking down broken configurations.
Upvotes: 0
Reputation: 3184
You need to turn off case sensitivity: change "gitdir:"
to "gitdir/i:"
[includeIf "gitdir/i:C:/Work/"]
path = .gitconfig-work
[includeIf "gitdir/i:C:/My/Dev/"]
path = .gitconfig-my
from:
https://github.com/Microsoft/vscode/issues/62921#issuecomment-437693020
Upvotes: 36
Reputation: 21706
There is a typo here:
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
path = .gitconfig-work
There should be no space after gitdir:
:
[includeIf "gitdir:~/Documents/webstorm/corporate/"]
path = .gitconfig-work
Removing it will correct the behavior within an initialized Git repository.
This will show the entire Git configuration and what Git config files it is drawn from:
git config --list --show-origin
CAVEAT: If you run this inside a Git repository it will show values from .gitconfig-work, but it will not if you are within ~/Documents/webstorm/corporate/, but outside a Git repository.
Upvotes: 10
Reputation: 18221
The accepted answer, while helpful, does not answer the question.
As of this writing, includeIf only works inside a git initialized folder.
So if you cd into "~/Documents/webstorm/corporate/somegitproject" and run the command the output will be as expected:
$ cd ~/Documents/webstorm/corporate/somegitproject
$ git config user.email
[email protected]
This is probably a defect against git, since a user would expect this to work similarly in "~/Documents/webstorm/corporate/" as well.
Upvotes: 31
Reputation: 2138
Your global C:/Users/<user-name>/.gitconfig
should have this includeIf
:
[includeIf "gitdir:C:/Users/<user-name>/Documents/webstorm/corporate/"]
path = .gitconfig-work
with having your work Git repos in C:/Users/<user-name>/Documents/webstorm/corporate
and the conditional
work configuration should be located at C:/Users/<user-name>/.gitconfig-work
.
That's at least working for me in Window's cmd and Cmder. A git config --show-origin --get user.email
should than show you from where a config value is loaded/resolved.
It also seems like the conditional
work configuration is only used when issued from within a Git repository.
C:\Users\<user-name>\Documents\webstorm\corporate
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig [email protected]
C:\Users\<user-name>\Documents\webstorm\corporate\some-repo
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig-work [email protected]
C:\Users\<user-name>\Documents\webstorm\corporate\some-non-repo-dir
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig [email protected]
Upvotes: 81