How to configure multiple git profiles
Having different git profiles configured in the same computer becomes very handy when you use the same machine to develop both professional and personal projects — as it’ll allow you to push commit messages with different user profiles based on the repository.
In this blog, I’ll assume that you have a folder structure similar to the one below. If you don’t follow this structure, the modifications you need to make are very straightforward.
In your user’s home directory, you should create a .gitconfig file. If you already have one, please only add the content from the following GitHub Gist.
Each git profile that you want to create should be represented by an includeIf
section. This condition tells git in which directory and sub-directories the configuration should be applied.
Path variable should have the location of the .gitconfig file, that contains the user configuration to be used in the repositories under that directory.
After this step, for each parent directory — in our example, C:\Personal\
& C:\Work\
— you need to create another .gitconfig, where you configure your user details.
Hope you have found this blog useful, and that the management of your git profiles has become simpler now.
You can find me on GitHub and Stack Overflow.