We want our work-related stuff to be committed with our work emails. It is often difficult to manage two different gitconfigs. We have to put separate gitconfigs in each work-related repository.
Git 2.13 has
conditional includes which can be used to make this easy.
Assuming we have a separate directory for all work-related projects named
create a file
[user] name = Tejas Bubane email = firstname.lastname@example.org
And add this to the bottom of your main
[includeIf "gitdir:~/work/"] path = .gitconfig-work
We are telling git to include
.gitconfig.work only if the project is in
includeIf expands the config immediately in place (as good as writing it there).
Hence for the overriding to take effect, the include should be below your original config.
This way for work project we use the work email, for all others we use the personal email.
This is just an example of email, but you can override any git config using conditionals.
1 . Conditional config documentation: https://git-scm.com/docs/git-config#_includes
2 . Git
2.13 release notes: https://github.com/blog/2360-git-2-13-has-been-released