
How to Use Multiple Git Accounts (Personal + Work) on the Same Laptop with Verified Commits
๐ How to Use Multiple Git Accounts (Personal + Work) on the Same Laptop (with Verified Commits)
So youโve got two GitHub accounts โ
one for your personal projects and another for your company.
You clone a repo, make a commit... and oops ๐ฌ GitHub shows itโs from the wrong account.
Or worse โ unverified commit โ
Donโt worry! This guide will walk you through everything step-by-step โ for Linux, macOS, and Windows users.
๐งฐ Demo Setup
Letโs say:
| Feature | Personal Git | Work Git |
|---|---|---|
| User Identity | ๐ค abhishek-personal | ๐ abhishek@company.com |
| Config File | ~/.gitconfig-personal | ~/.gitconfig-work |
| Repo Location | ~/personal/ | C:\My Code\GitHub\LexiPitch |
| Email Used | ๐ง personal@gmail.com | ๐ง work@company.com |
| Authentication | SSH: personal_ssh_key | SSH: work_ssh_key |
| When Used | ๐ป Freelance / side projects | ๐ข Company / official work |
Weโll use these throughout the tutorial.
๐ป System Notes
โ The main commands below are for Linux/macOS.
For Windows (PowerShell), replace:
~โC:\Users\<YourName>nanoโnotepadeval "$(ssh-agent -s)"โStart-Service ssh-agent
๐น Step 1: Generate Separate SSH Keys
Generate keys for both accounts. These act as your digital fingerprints.
Now youโll have:
~/.ssh/id_ed25519_personal
~/.ssh/id_ed25519_personal.pub
~/.ssh/id_ed25519_work
~/.ssh/id_ed25519_work.pub
๐น Step 2: Start ssh-agent and Add Keys
Letโs tell your system to remember your keys.
Linux/macOS:
Windows (PowerShell):
Start-Service ssh-agent
ssh-add "C:\Users\<YourName>\.ssh\id_ed25519_personal"
ssh-add "C:\Users\<YourName>\.ssh\id_ed25519_work"
๐น Step 3: Create SSH Config File
This file tells Git which key to use for which account.
Add this content:
# Personal GitHub
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitHub
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
Save and close the file.
๐น Step 4: Add SSH Keys to GitHub
Display your public keys:
Then:
- Go to GitHub โ Settings โ SSH and GPG Keys โ New SSH key.
- Paste each key into the right account.
๐น Step 5: Clone Repositories
When cloning, use the correct host alias:
Notice the difference? Weโre telling Git which SSH identity to use.
๐น Step 6: Set Your Identity per Repo
Inside each cloned repo:
For work repo:
This ensures commits are tagged with the correct name and email.
๐น Step 7: Generate GPG Keys (for Verified Commits โ )
Letโs add that sweet green โVerifiedโ badge next to your commits.
Choose:
- RSA and RSA โ Option
1 - Key size โ
4096 - Expiry โ
1y(optional) - Email โ Match your GitHub email
- Name โ Your Name
Repeat this for both accounts.
๐น Step 8: Find and Copy Your GPG Key ID
List all GPG keys:
Example output:
sec rsa4096/ABCD1234EFGH5678 2025-01-01 [SC]
ABCD1234EFGH5678ABCD1234EFGH5678ABCD1234
uid [ultimate] Your Name <personal@example.com>
Copy the key ID after the /, for example:
ABCD1234EFGH5678
Then export it to copy:
Paste this into GitHub โ Settings โ SSH and GPG keys โ New GPG key.
๐น Step 9: Tell Git to Sign Commits Automatically
Inside your repo:
Then add your key:
Now every commit you make will be verified โ .
๐น Step 10: Automate with Conditional Git Config
If you switch between repos often, automate your identity!
Add this to your global Git config:
Then create the two files:
~/.gitconfig-work:
[user]
name = Work Dev
email = work@company.com
signingkey = WORKGPGKEY123
~/.gitconfig-personal:
[user]
name = Personal Dev
email = personal@example.com
signingkey = PERSONAGPGKEY123
Now Git automatically switches identity depending on which folder youโre in. ๐ฏ
๐น Full .gitconfig Example
Hereโs a working global config:
# ~/.gitconfig
[user]
name = Default Dev
email = default@example.com
[core]
editor = code --wait
[includeIf "gitdir:~/work/**"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/personal/**"]
path = ~/.gitconfig-personal
๐ง Verification Test
To check which identity Git is using inside any repo:
โ Your Final Workflow
- Clone repos with the right SSH alias
- Git auto-selects the right SSH key & GPG key
- Verified commits appear for both accounts
- No more โoops wrong accountโ moments
๐ฏ Final Thoughts
You just mastered multi-account Git setup with verified commits โ like a pro! This one-time setup saves you countless headaches later.
๐ Set it once ๐ Forget forever ๐ Push with confidence ๐
Written with โค๏ธ for every developer tired of Git yelling at them.