Issue
I'm on Ubuntu. Here's ~/.gitconfig
[user]
email = [email protected]
name = doug
[includeIf "gitdir:~/Projects/Work/"]
path = ~/.git-work
Here's ~/.git-work
[user]
email = [email protected]
name = doug-work
On the terminal if I cd into ~/Projects/Work/
and then check my username or email:
git config user.name
doug
git config user.email
[email protected]
Since I'm in directory ~/Projects/Work
I expected my git username and password to be doug-work
and [email protected]
but my personal Github username and email are showing instead.
How can I use includeIf so that if I'm in ~/Projects/Work
git uses my work github settings?
Solution
The directory /~Projects/Work
is not part of a Git repository. Therefore, gitdir
is not defined and does not match ~/Projects/Work/
.
If you cd
into a Git repository inside ~/Projects/Work/
, this should work.
Answered By - Elias Holzmann