Last update: 30-01-2024
Last view: 30-01-2024
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 protected]
The 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
It should have something like:
[user]
name = Icaruk
email = [email protected]
That'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 "[email protected]"
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-work
that 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 = [email protected]
[includeIf "gitdir:F:/Work/EnterpriseName/"]
path = F:/Work/EnterpriseName/.gitconfig-work
MacOS and Linux:
[user]
name = Icaruk
email = [email protected]
[includeIf "gitdir:~/Work/EnterpriseName/"]
path = ~/Work/EnterpriseName/.gitconfig-work
If it doesn't work, try removing the
~
Go to your work folder and open any project, then run:
> git config user.email
It 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.
In the step 2, email of .gitconfig no is the same as of command's value (git config --global user.email). Missing 'my'