DEV Community

Ariel Bogdziewicz
Ariel Bogdziewicz

Posted on

Git config for repositories in subdirectory

Quick hint for developers working on source code from different Git accounts having different e-mails for them. Let say we develop our own projects and we support development for two other companies. Our folder structure could look like


Of course we have configured default config as follows

user@mymac ~/ $ git config "Firstname Lastname"
user@mymac ~/ $ git config ""
user@mymac ~/ $ git config push.default simple
user@mymac ~/ $ git config core.editor emacs

We want different e-mails by default for all repositories in these directories without configuring this manually with command

user@mymac ~/CompanyAbc/website-repo (master) $ git config ""

every time when wy clone new repository.


Main ~/.gitconfig file should look like

        name = Firstname Lastname
        email =
        default = simple
        editor = emacs
[includeIf "gitdir:~/CompanyAbc/"]
        path = ~/CompanyAbc/.gitconfig
[includeIf "gitdir:~/CompanyMno/"]
        path = ~/CompanyMno/.gitconfig

Set custom e-mail address in ~/CompanyAbc/.gitconfig

        email =

You can repeat this for other configurations like ~/CompanyMno/.gitconfig too.


Please execute command to verify new settings

user@mymac ~/CompanyAbc/some-repo/ (master) $ git config

It should throw out something like

Good luck with coding!

Top comments (3)

jonatasoc profile image
Jonatas de Oliveira Coêlho

Awesome! Helped a lot! Thx!

aravin profile image
Aravind A

This is not working for me

altryne profile image
Alex V

Thank you for this quick tip! This is very helpful for folks who are signing their commits as well!