DEV Community

Franz Wong
Franz Wong

Posted on

2 2

Set different email address for multiple git repositories

Problem

I use my own laptop to code for both personal and work projects. However, I want to use my work email address only for my work projects. But I am lazy to set it for each repository.

Here is my folder structure. All work projects are under the same folder ~/src/work. Other projects are personal projects.

~/src/work/project-i        # work project
~/src/work/project-j        # work project
~/src/playground/project-a  # personal project
~/src/bots/project-b        # personal project
~/src/devops/project-c      # personal project
Enter fullscreen mode Exit fullscreen mode

Solution

Step 1. Add an includeIf section to global git config file ~/.gitconfig. (Create this file if it does not exist)

[user]
    name = Franz
    # personal email address
    email = franz@whatever.com

[includeIf "gitdir:~/src/work/"]
    path = ~/src/work/.gitconfig
Enter fullscreen mode Exit fullscreen mode

Step 2. Add the work email address to our work git config file ~/src/work/.gitconfig. (Create this file if it does not exist)

[user]
    # work email address
    email = franz@serious.com
Enter fullscreen mode Exit fullscreen mode

After you have done these steps, when you commit code to your work projects, the email used in commit will be your work email address.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay