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

2025-10-0215 Minutes
gitgithubgpgsshdeveloper-tools

🚀 How to Use Multiple Git Accounts (Personal + Work) on the Same Laptop with Verified Commits

Let me guess — you’re working on side projects at 2 AM (because that’s when real devs come alive 🌙) but during the day you’re pushing commits for your company repo.

Suddenly, Git screams at you:

“Wait… are you [email protected] or [email protected] today? 🤔”

Been there. Done that. Accidentally committed company code with my personal email back in 2011 (don’t ask how many people saw it).

So today, from my 30 years of wrestling with Git dragons 🐉, I’ll show you how to set up multiple Git accounts with verified commits — the right way.
No more config flip-flopping. No more unverified commits. No more “who the heck is BobTheBuilder123 on our company repo?” moments.


🔹 Why This Is Important (a story…)

Imagine you’re in a team meeting.
Boss pulls up GitHub.
You see:

  • main branch ✔
  • Last commit: “Fix prod bug 🐛” — by Anonymous Dev (unverified)

Now the boss looks around. Awkward silence.
That’s what happens when you don’t separate accounts properly.

We’re going to fix that forever.


🔹 Step 1: Generate Separate SSH Keys

Think of SSH keys like house keys.
You don’t want your work office key also opening your gaming PC.

# Personal account ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_personal # Work account ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_work

Now you have two keys safely tucked away:

  • ~/.ssh/id_ed25519_personal
  • ~/.ssh/id_ed25519_work

🔹 Step 2: Add Keys to ssh-agent

This is like giving your system a “memory” of your keys so you don’t type them every 2 minutes.

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519_personal ssh-add ~/.ssh/id_ed25519_work

🔹 Step 3: SSH Config (Git’s Secret Sauce)

Open your SSH config file:

nano ~/.ssh/config

Paste this magic spell:

# 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

From now on, Git won’t get confused which key to use. 🎉


🔹 Step 4: Add SSH Keys to GitHub

Print the keys and paste them into GitHub → Settings → SSH and GPG keys:

cat ~/.ssh/id_ed25519_personal.pub cat ~/.ssh/id_ed25519_work.pub
  • Personal key → add to your personal GitHub.
  • Work key → add to your company GitHub.

🔹 Step 5: Clone Repos the Smart Way

When cloning:

# Personal repo git clone [email protected]:username/personal-repo.git # Work repo git clone [email protected]:company/repo.git

Notice the github.com-personal vs github.com-work? That’s the trick.


🔹 Step 6: Git Identity Per Repo

Inside each repo, set who you are:

# Personal repo git config user.name "Your Personal Name" git config user.email "[email protected]" # Work repo git config user.name "Your Work Name" git config user.email "[email protected]"

No more mixing identities.


🔹 Step 7: GPG Keys for Verified Commits ✅

That little green check mark on GitHub commits isn’t just for show — it’s proof you’re the real deal. Here’s how you get it:

gpg --full-generate-key
  • Type: RSA and RSA (1)
  • Size: 4096
  • Expiry: 1 year (renew later if needed)
  • Email: MUST match GitHub email

Repeat for both work and personal accounts.


🔹 Step 8: Copy GPG Keys

List your keys:

gpg --list-secret-keys --keyid-format=long

You’ll see something like:

sec   rsa4096/ABCD1234EFGH5678 2025-01-01 [SC]
      ABCD1234EFGH5678ABCD1234EFGH5678ABCD1234
uid           [ultimate] Your Name <[email protected]>

Export the public key:

gpg --armor --export ABCD1234EFGH5678

Add it in GitHub → Settings → SSH and GPG Keys → New GPG Key.


🔹 Step 9: Tell Git to Sign Commits

Inside your repo:

# Enable signing git config commit.gpgsign true # Use your key (replace with real one) git config user.signingkey ABCD1234EFGH5678

Now every commit shows that beautiful green badge ✅.


🔹 Step 10: The Senior Dev Hack — Conditional Git Config

Tired of setting user/email in every repo? Let’s automate:

git config --global includeIf."gitdir:~/work/".path ~/.gitconfig-work git config --global includeIf."gitdir:~/personal/".path ~/.gitconfig-personal

Create ~/.gitconfig-work:

[user]
    name = Work Dev
    email = [email protected]
    signingkey = <work_gpg_key_id>

And ~/.gitconfig-personal:

[user]
    name = Night Owl Hacker
    email = [email protected]
    signingkey = <personal_gpg_key_id>

Now Git switches brains automatically based on the folder. 💡


🎁 Bonus: Full .gitconfig Template

Here’s a ready-to-use config you can tweak:

# ~/.gitconfig
[user]
    name = Default Dev
    email = [email protected]

[core]
    editor = code --wait

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

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

✅ Final Workflow

  • Clone repos with the right host (github.com-work vs github.com-personal).
  • Git auto-selects the right SSH key + GPG key.
  • Verified commits for both personal and work.
  • No late-night “oops wrong account” moments.

🎯 Closing Thoughts

After 30 years with Git (yes, I survived the SVN → Git migration wars ⚔️), here’s my advice:

👉 Invest 30 minutes to set this up once. 👉 Save hundreds of hours fixing mistaken commits later.

You’ll thank me the next time your boss asks, “Who pushed this bug to production?” — and your verified commit proudly says, not me. 😉