Last update: 30-01-2024
Last view: 01-05-2025
Go to your work folder, mine is located at:
F:/Work/EnterpriseName/
And then create a .gitconfig-work with the following data:
[user]
name = Name at work
email = email@atwork.comThe folder should be like this:
π EnterpriseName
ββ π project01
ββ π project02
ββ π project03
ββ π .gitconfig-work
Navigate to your current .gitconfig and open it.
Usually it's at C:\Users\your-user or ~/Users/your-user.
It should have something like:
[user]
name = Icaruk
email = myemail@hotmail.comThat's the global config, that will be used as the default one. If it doesn't exist, create it with these commands:
> git config --global user.name "Icaruk"
> git config --global user.email "myemail@hotmail.com"Add the following lines below:
[includeIf "gitdir:F:/Work/EnterpriseName/"]
path = F:/Work/EnterpriseName/.gitconfig-work- The first path is your work path, it must end with "/".
- The second path is your
.gitconfig-workthat you created on your work folder. But it can be anywhere, just point at it.
[user] data block. More info at mi6th comment.
The resulting file should be like this:
Windows:
[user]
name = Icaruk
email = myemail@hotmail.com
[includeIf "gitdir:F:/Work/EnterpriseName/"]
path = F:/Work/EnterpriseName/.gitconfig-workMacOS and Linux:
[user]
name = Icaruk
email = myemail@hotmail.com
[includeIf "gitdir:~/Work/EnterpriseName/"]
path = ~/Work/EnterpriseName/.gitconfig-workIf it doesn't work, try removing the
~
Go to your work folder and open any project, then run:
> git config user.emailIt should display your work email.
Now go to any project that isn't located inside your work folder and run the same command. It should display your default email.
Here is how to use it with remote repo services like gitlab.com, for instance https://docs.gitlab.com/ee/user/project/repository/signed_commits/gpg.html#set-signing-key-conditionally