Multiple Git Configurations View article history Edit article

Published: , Updated:
Talks about: <a class="post-tag post-tag-config" href="/tags/config">config</a>, and <a class="post-tag post-tag-git" href="/tags/git">git</a>

To split yet re-use as much configuration for Git as possible, you can create one root configuration that looks similar to this:

  name = Your Name Here

[includeIf "gitdir:~/git/personal/"]
  path = ~/.config/git/personal
[includeIf "gitdir:~/git/work/"]
  path = ~/.config/git/work

The includeIf directive supports multiple keywords. In my case, work and personal projects have a different root directory, therefore I can filter based on the location using gitdir. The personal Git configuration simply looks like this:

  email = [email protected]

and the work related configuration like this using a different email address:

  email = [email protected]

Additional settings that are different for personal/work accounts can be split the same way, for example to use a different signing key for work.