1. 程式人生 > >Using different Git emails @ Alex Pliutau's Blog

Using different Git emails @ Alex Pliutau's Blog

Usually at work and at home we use different Git name/email pairs, or even per project. Pushing with correct email guarantees that your commits will be authored with a correct user identity.

This configuration stored in .gitconfig file and looks like:

[user]
    name = Alex Pliutau
    email = [email protected]

Git 2.13 introduces conditional configuration includes. For now, the only supported condition is matching the filesystem path of the repository, but that’s exactly what we need in this case. You can configure two conditional includes in your home directory’s ~/.gitconfig file:

[user]
    name = Alex Pliutau
    email = 
[email protected]
[includeIf "gitdir:~/wzln/"] path = ~/.gitconfig-wzln

~/.gitconfig-wzln

[user]
    name = Alex Pliutau
    email = [email protected]

Note: To check it, make sure you are in a Git directory, non-Git directories will always show the default configuration.