Home

Easiest way to manage multiple Git users on the same computer

Want to be able to push code to work and personal projects without needing to switch git users all the time?

The short guide bellow might be for you!

Easy 3 Step Solution

The most straight forward solution for me is to have separate work and personal folders with different .gitconfig files.

Here is a quick 3 step guide.

1. Separate all personal project from work projects

Do:

/home
    /personal-projects        # Do this        /personal-project1
        /personal-project2
    /work-projects            # Do this        /work-project1
        /work-project2

Don’t:

/home
    /projects                # Don't do that        /personal-project1
        /personal-project2
        /work-project1
        /work-project2

2. Create different .gitconfig files

Inside each of these folders, add a individual .gitconfig file:

/home
    /personal-projects
        .gitconfig        /personal-project1
        /personal-project2
    /work-projects
        .gitconfig        /work-project1
        /work-project2

Edit each .gitconfig file and add the relevant account for that folder:

home/personal-projects/.gitconfig
[user]
    email = devimal.planet@work.com
    name = Devimal Planet
home/work-projects/.gitconfig
[user]
    email = relaxed.devimal@home.com
    name = Relaxed Devimal

3. Last step: Edit the main .gitconfig file

Edit the global .gitconfig, so it chooses the correct configuration on its own.

On Unix this file can be found at ~/.gitconfig. On Windows: C:\Users<Your user>.gitconfig.

home/.gitconfig
[user] # If local config does not exist, this user is used.
    name = Devimal Global
    email = devimal@global-configuration.com

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

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

Bonus Tips

Can’t find your config file?

Try this in a terminal window if for some reason you cannot find your .gitconfig file:

git config --list --show-origin

Windows user?

Use gitdir/i and full path with forward slash:

C:\Users<Your user>.gitconfig
[includeIf "gitdir/i:C:/Users//Desktop/personal-projects/"]
    path = C:/Users//Desktop/personal-projects/.gitconfig

Not working?

This will only affect future projects created with git init. Previous projects will remain unchanged.