DEV Community

Cover image for Managing multiple Git profiles
Rahul Jha for DeepSource

Posted on • Updated on • Originally published at

Managing multiple Git profiles

If you use git as the version control tool for both your personal projects and at work, chances are that you want to isolate the two (or more) profiles, i.e. at the very least, using different emails for creating commits and tags. Other uses might include using different usernames (for different GitHub accounts), gpg-keys, etc.

One straightforward way of tackling this is to remember setting the correct configuration whenever you clone (or initialize) a new repo:

git config "priam"
git config ""
Enter fullscreen mode Exit fullscreen mode

Besides, being painstakingly mundane, it is yet another thing to remember. Nevermind the time and effort of rewriting history if you have already created commits.

But wait, there's a better way

Git offers a much more flexible way of specifying conditional config files based on your current directory β€” if you use a different directory for all your work repos (let's say ~/work/), then you can specify the following in your ~/.gitconfig to automatically use your work credentials inside them:

    path = ~/git-personal.conf
[includeIf "gitdir:~/work/"]
    path = ~/git-work.conf
Enter fullscreen mode Exit fullscreen mode

Each conf file can then define it's own user, e.g. ~/git-personal.conf:

    name = realerlich
    email = erlich@hacker.hostel
    signingkey = FF5353EC154B6811
Enter fullscreen mode Exit fullscreen mode

and ~/git-work.conf:

    name = erlich
    email =
    signingkey = CE3454AA132E6F2E
Enter fullscreen mode Exit fullscreen mode

There, all set now! Whenever you are working inside a repo that lives under ~/work, Git will automatically use your work email. Go ahead, try it out!

EDIT: Note that any configuration can be bifurcated in this way. It need not be just these user-specific fields, and neither is it also required to specify all of these.

EDIT 2: In case you want to find out signingkey, head here -

[This blog post originally appeared on]

Top comments (4)

zakariatalhami profile image

I currently have this set up on my laptop. It allows me to switch between work and personal accounts seamlessly, even to the point that I dont think of the difference.

rj722 profile image
Rahul Jha

Woot! πŸŽ‰

rkichenama profile image
Richard Kichenama

Would this also require different ssh identities for pushing deltas?

rj722 profile image
Rahul Jha

I don't think that the SSH configuration is coupled with Git. It is handled differently as a part of ~/.ssh/config.