DEV Community

nop33.eth
nop33.eth

Posted on • Originally published at iliascreates.com on

Authoring commits with different emails for work and personal projects

I like to store all my git repositories, of both work and personal projects, under a single directory at ~/dev. I think I’ll change this to ~/code soon, it sounds more appropriate. Anyway, back to the topic.

At the top of my ~/.gitconfig file I have configured the git user (which represents the commit author) to use my personal email address:

[user]
  name = Ilias Trichopoulos
  email = ilias.personal@gmail.com
Enter fullscreen mode Exit fullscreen mode

However, when I work in git repositories of projects for my work, I want the author of my commits to have my work email address. The simplest way I found to achieve this is to dedicate a directory for all my work-related git repositories and create a separate .gitconfig file there. Then, I can conditionally include this new file in my main .gitconfig depending on which project I am working on.

In my case, I have all my work-related projects under ~/dev/company-name. I created a new .gitconfig file there where the only contents are:

[user]
  email = ilias.work@company-name.com
Enter fullscreen mode Exit fullscreen mode

Git 2.13 introduced the feature of Conditional includes which allows you to include a dedicated .gitconfig file depending on where the git repository is located.

Adding the following configuration at the bottom of my main ~/.gitconfig file ensures that when I work in a git repository located at ~/dev/company-name/project1, the author of my commits will have the ilias.work@company-name.com email address.

[user]
  name = Ilias Trichopoulos
  email = ilias.personal@gmail.com

...

[includeIf "gitdir:~/dev/company-name/"]
  path = ~/dev/company-name/.gitconfig
Enter fullscreen mode Exit fullscreen mode

Credits to this StackOverflow answer that showed me the way.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

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

Okay