Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git includeIf for personal and work profiles doesn't work

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.

✨ For the future googlers

I created a gist explaining the steps.

like image 711
Icaruk Avatar asked May 01 '20 13:05

Icaruk


People also ask

Can I have multiple users in Gitconfig?

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.

Does git config local override global?

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.

Where does git store all global configuration?

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.


1 Answers

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.)

like image 183
torek Avatar answered Oct 26 '22 18:10

torek