Start now →

How to Use Multiple Git Accounts on One Machine (Work & Personal)

By Babajide Awodire · Published March 30, 2026 · 5 min read · Source: Level Up Coding
Blockchain
How to Use Multiple Git Accounts on One Machine (Work & Personal)

Introduction

Brief context on why this is really useful — multiple companies, personal projects, the frustration of wrong commits or push errors.

💡 Why This Is Useful

If you contribute to code across multiple Git accounts.
for example, one for your day job, another for personal projects, and maybe even a freelance client

it’s easy to run into issues:

This guide helps you avoid all of that. With the right setup, Git will automatically use the correct identity, email, and SSH key — all based on the folder your repo is in. No more manual switching. No more commit regrets.

🧠 What You’ll Learn

🧭 Step-by-Step Overview

Here’s a breakdown of what we’ll cover in this guide:

🔑 Step 1: Generate SSH Keys for Each Account

Create separate SSH keys for your work and personal Git profiles.

🧹 Step 2: Remove Global Git User Identity

Clear your global Git user config to prevent accidental misattribution.

📂 Step 3: Create a Config Directory for Git

Set up a dedicated directory to manage Git config files for each account.

📄 Step 4: Create Separate Config Files for Each Account

Add work.config and personal.config to store identity and SSH info.

✍️ Step 5: Set Account Info in Each Config File

Define your name, email, and SSH command in each respective config file.

🗂️ Step 6: Organize Your Repositories by Context

Structure your projects into ~/dev/work/ and ~/dev/personal/.

⚙️ Step 7: Use Conditional Includes in Your Git Config

Configure Git to load the right settings based on the repo’s location.

🧪 Step 8: Test the Setup

Verify that Git uses the correct identity and SSH key for each repo.

✅ Conclusion

Optional: Skip the SSH setup if you use HTTPS and access tokens instead.

🛠️ The Step-by-Step Guide

Follow these steps to set up multiple Git profiles with their own SSH keys and identities.

🔑 Step 1: Generate SSH Keys for Each Account

# For work
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/work_id_ed25519

# For personal
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/personal_id_ed25519
work_id_ed25519
work_id_ed25519.pub
personal_id_ed25519
personal_id_ed25519.pub
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/personal_id_ed25519
ssh-add ~/.ssh/work_id_ed25519
# ~/.gitconfig
# Remove or comment out this block:
# [user]
# name = Your Name
# email = [email protected]

📂 Step 3: Create a Config Directory for Git

mkdir -p ~/.config/git

📄 Step 4: Create Separate Config Files for Each Account

touch ~/.config/git/work.config
touch ~/.config/git/personal.config
ls ~/.config/git
# Output:
# personal.config
# work.config

✍️ Step 5: Set Account Info in Each Config File

[user]
name = Your Name
email = [email protected]

[core]
sshCommand = "ssh -i ~/.ssh/personal_id_ed25519"
[user]
name = Your Name
email = [email protected]

[core]
sshCommand = "ssh -i ~/.ssh/work_id_ed25519"

🗂️ Step 6: Organize Your Repositories by Context

~/dev/work/      # All work-related repos
~/dev/personal/ # All personal projects repos

Clone or move your repos into the appropriate folders.

⚙️ Step 7: Use Conditional Includes in Your Git Config

Open ~/.gitconfig and add conditional logic to include the right config based on directory:

[includeIf "gitdir:~/dev/work/"]           # the path to the work directory
path = ~/.config/git/work.config # the path to the work config

[includeIf "gitdir:~/dev/personal/"] # the path to the personal directory
path = ~/.config/git/personal.config # the path to the personal config

💡 Pro Tip: Make sure the path = lines don’t have quotes — just a plain file path.

🧪 Step 8: Test the Setup

cd ~/dev/personal/my-side-project
git config user.name
git config user.email
git config core.sshCommand
git config --list

You should see your personal identity.

cd ~/dev/work/cool-client-project
git config user.name
git config user.email
git config core.sshCommand
git config --list

You should see your work identity.

✅ Conclusion

With this setup, you no longer have to worry about using the wrong Git identity across different projects. Everything works automatically based on where your repo lives — clean, efficient, and frustration-free.

However, if you use HTTPS with personal access tokens (like GitHub or GitLab tokens) instead of SSH, you can skip the SSH setup entirely.

In that case, all you need in each config file is:

[user]
name = Your Name
email = [email protected]

If this guide saved you from yelling at Git in frustration, go ahead and give it a clap — it helps more devs find it.

So moving forward, more helpful, no-nonsense dev content is on the way, so feel free to follow me if you’re into clean setups, productivity hacks, and an occasional rant about Tech generally.

Thanks for reading — now go commit responsibly 👏!


How to Use Multiple Git Accounts on One Machine (Work & Personal) was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.

This article was originally published on Level Up Coding and is republished here under RSS syndication for informational purposes. All rights and intellectual property remain with the original author. If you are the author and wish to have this article removed, please contact us at [email protected].

NexaPay — Accept Card Payments, Receive Crypto

No KYC · Instant Settlement · Visa, Mastercard, Apple Pay, Google Pay

Get Started →