Two git accounts, one device.

Personal vs Work


2 min read

I just started working and was asked to create a new GitHub account for my work-related tasks. But there was one major issue when it came to setting up git on my machine. How do I handle personal commits and work-related commits?

General git setup

git config --global "John Doe"
git config --global ""

Issues with this approach

  1. Change the global config every time before you commit to a different account.

  2. Create repository-specific configurations.

# personal repos
git config "John Doe"
git config ""

# work repos
git config "John Doe"
git config ""

But this is a huge inconvenience. You might accidentally commit to your work repository using your personal credentials! Or every time you create a git repo for personal use, you'll have to set up the config. Ugh! Luckily, there's an easy way out!


It is a bit involved with the config files, but it's a one-time thing. Create three files.


### ~/.gitconfig.personal
  name        = John Doe
  email       =
  signingkey  = JDPERSONAL


  name        = John Doe
  email       =
  signingkey  = JDPROFESSIONAL


[includeIf "gitdir:~/company/**/.git"]
  path = ~/

  path = ~/.gitconfig.personal

Now all your commits inside the ~/company directory will use your company credentials, and all other commits will use your personal credentials!