DEV Community

Ariel Bogdziewicz
Ariel Bogdziewicz

Posted on

9 1

Git config user.email 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

~/.gitconfig
~/PersonalProjects/
~/CompanyAbc/.gitconfig
~/CompanyMno/.gitconfig

Of course we have configured default config as follows

user@mymac ~/ $ git config user.name "Firstname Lastname"
user@mymac ~/ $ git config user.email "user@myprivatebox.com"
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 user.email "user@company-abc.com"

every time when wy clone new repository.

Solution

Main ~/.gitconfig file should look like

[user]
        name = Firstname Lastname
        email = user@myprivatebox.com
[push]
        default = simple
[core]
        editor = emacs
[includeIf "gitdir:~/CompanyAbc/"]
        path = ~/CompanyAbc/.gitconfig
[includeIf "gitdir:~/CompanyMno/"]
        path = ~/CompanyMno/.gitconfig

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

[user]
        email = user@company-abc.com

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

Verification

Please execute command to verify new settings

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

It should throw out something like

user@company-abc.com

Good luck with coding!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (3)

Collapse
 
jonatasoc profile image
Jonatas de Oliveira Coêlho

Awesome! Helped a lot! Thx!

Collapse
 
aravin profile image
Aravind A

This is not working for me

Collapse
 
altryne profile image
Alex V

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

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post