How to use multiple github accounts in one PC?
Need to work with multiple GitHub accounts on one computer? This step-by-step tutorial configuration seeting or command reuquired to manage multiple git accounts. Boost your productivity by easily handling personal and professional projects on GitHub with this guide.
by Abhishek Singh
6 min read
28th March, 2025
When you’re working on your personal projects or your work, you might be using two separate Git accounts. To avoid switching the username and email ID every time, you might want easier access to the GitHub account. Here, we will discuss two simple approaches:
.gitconfig
modification based on folder locationGit uses the
.gitconfig
file in the user directory for its main config. When a terminal or command prompt opens up, these configs are also loaded. We can add logic inside the .gitconfig
to load our Git config file based on the directory.Configuration Steps:
Step 1: First, create multiple separate config files based on usage. For now, we will see how to configure two separate accounts:
For personal usage, create .gitconfig_personal
in the user folder:
[user] name = <Your name>; email = <your personal email id connected to GitHub>;
For work usage, create .gitconfig_work
:
[user] name = <Your name>; email = <your work email id connected to GitHub>;
Step 2: Open the .gitconfig
file and modify it:
[user] email = <Default Email Id> name = <Your Name> [includeIf "gitdir:C:/Workspace/personal/"] path = <your user directory location>/.gitconfig_personal [includeIf "gitdir:C:/Workspace/work/"] path = <your user directory location>/.gitconfig_work
This code specifies that for the given gitdir, use the config file specified in the path. Any number of includeIf directives can be added based on usage.
Note:- Make sure to end the path in gitdir with / ; otherwise, changes won’t take effect.
- Same configuration can be used if SSH is used, use SSH config.
- More details regarding gitdir can be found at Git Documentation - gitdir
Approach 2: Using --
local parameter:
There is another way to overwrite the default .gitconfig file. You can use a local config file. This is useful when a user is working with multiple GitHub accounts and finds it difficult to manage different directories.
Go to your cloned repository path:
cd /path/to/your/repository
Create a local GitHub file using the command:
git config --local user.name "Your Name" git config --local user.email [email protected]
This will create a local config file for the repository and will be used for git operations when working in that repository directory.