Jenish Jain

How to manage multiple git users on a single system

An easy way to contribute with multiple github profiles using a single system

Jenish Jain
written by Jenish

Having problems managing your multiple personalities?
well this can be resolved for git using these simple steps.🪄

Problem

Most of us have atleast two github profiles one for work and another personal and contributing to both of them with separate accounts could be a pain. while one can always remember and switch their profiles, but we can do a better job here using some configurations.

Solution

Assuming you have a usual setup of a workspace and a personalspace which you use to organise your work and personal projects and the structure looks something like this.


folder structure


We can take advantage of gitconfigs here to instruct git to use a particular set of credentials in a given space.

We have a .gitconfig file at the root level which maintains your global git configuration. what we are gonna do is store individual git config in your pesonal and work folders and tell .gitconfig to replace the user and credentials according to the space you are in.

create space specific config files

we will have to create .config files in each folder something like this.

git-config


after creating both the config files your folders should looks like this.

folders-with-gitconfig

configuring your global git config

now in your global ~/.gitconfig file we need to replace the [user] block with the one shown below ( for me both workspace and personal space were present on desktop)

global git config

Thats All 🎉

now you can simply navigate to your desired space and work without worrying about commiting with correct git profile.

Test if this is working 👀

we can test this by simply creating a test project and initialising git in it. on checking the local config you should see the appropirate username and email configured.

personalspace-test

workspace-test

References