I've been googling about this, trying different methods from different sources... but it doesn't work.
I want to push commits with my personal profile (defined with "git config --global user.email ...") unless I'm on my work folder.
The content of my .gitconfig is located at C:/Users/my-user/
[user]
name = Personal
email = [email protected]
[includeIf "gitdir: F:/Work/CompanyName/"]
path = F:/Work/CompanyName/.gitconfig-work
Content of my .gitconfig-work is located at F:/Work/CompanyName/
[user]
name = Work
email = [email protected]
When I go to a cloned repository from work located at:
F:/Work/CompanyName/Project
I use:
git config --show-origin --get user.email
And it shows:
file:C:/Users/<my-user>/.gitconfig
Instead of the route I defined to work.
Thanks for your help.
I created a gist explaining the steps.
With conditional includes in Git 2.13, it is now possible to have multiple user/email coexist on one machine with little work. user. gitconfig has my personal name and email.
git config will only ever change one file at a time.You can override these rules using the --global , --system , --local , --worktree , and --file command-line options; see OPTIONS above.
The system level configuration file lives in a gitconfig file off the system root path. $(prefix)/etc/gitconfig on unix systems. On windows this file can be found at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer.
You need to remove one space in:
[includeIf "gitdir: F:/Work/CompanyName/"]
i.e., make this read:
[includeIf "gitdir:F:/Work/CompanyName/"]
Note the lack of a blank between the colon after gitdir
and the path name to be tested.
(Your Git also needs to be at least version 2.13. You might consider using gitdir/i:f:/work/companyname/
so that you are not case-sensitive here, assuming your host system is also not case-sensitive, as the F:
part suggests.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With