DEV Community

Sivasubramanyam A
Sivasubramanyam A

Posted on • Originally published at

Using different Git commit authors for personal and work projects

If you are somebody like me who has both personal and work projects in your development setup, you will probably be setting up the commit author each time you clone a repo.

While it's foolproof, it can feel annoying to do this often. I was looking for a solution to this and here's what I found.

It is possible to include .gitconfig files in other .gitconfig files. An interesting feature in Git is that you can do this conditionally.

Let's use this feature to our advantage now. In your ~/.gitconfig, do the following:

# ~/.gitconfig

    email =
    name  = Siva

[includeIf "gitdir:~/work/"]
    path = .gitconfig-work

What this does is that, it sets the commit author's name to Siva and email to When a repository's path starts with ~/work, it includes the configuration in .gitconfig-work. Now, if .gitconfig-work has the following contents, the commits in that repo alone will use the following user(essentially overriding the previous user).

# ~/.gitconfig-work

    email =
    name  = Mr. Siva

Using the above setup, all Git repositories, except the ones under the path ~/work/ use my personal details and the ones under ~/work are committed with my official details.

Top comments (2)

crumdev profile image
Nathan Crum

Thank you! Setting this up tonight. I was getting frustrated if I forgot to set my user.

satishgoda profile image
Satish Goda

This is awesome! Thank you for sharing this tip.