DEV Community

Cover image for How I Stopped Mixing Personal and Work GitHub Accounts
Adrian Darian
Adrian Darian

Posted on

How I Stopped Mixing Personal and Work GitHub Accounts

If you use more than one GitHub account, this probably sounds familiar.

You’re in the zone, commit, push… then notice the commit is tied to the wrong GitHub account. Wrong email. Wrong avatar. Wrong org.

I hit this problem often enough that I stopped trying to “be careful” and built a fix.


The real issue

Git makes this easy to mess up:

  • Global config applies everywhere
  • Local config is easy to forget
  • SSH config controls access, not identity
  • Hooks are per-repo and brittle

All of this relies on memory. Memory fails.

What I wanted was automatic guardrails.


The idea: identity follows location

The core idea behind gh-account-guard:

Your GitHub identity should be based on where you work, not what you remember to switch.

Example layout:

~/work/*        → work GitHub account
~/personal/*    → personal GitHub account
Enter fullscreen mode Exit fullscreen mode

Once defined, identity switching should be automatic.


Installation

gh-account-guard is a GitHub CLI extension.

gh extension install adriandarian/gh-account-guard
Enter fullscreen mode Exit fullscreen mode

Verify it’s installed:

gh account-guard --help
Enter fullscreen mode Exit fullscreen mode

Initial setup

Initialize your configuration:

gh account-guard init
Enter fullscreen mode Exit fullscreen mode

You’ll map directory paths to GitHub accounts, for example:

~/work        → company-account
~/personal    → adriandarian
Enter fullscreen mode Exit fullscreen mode

This only needs to be done once.


What happens during normal work

From here on, the workflow is simple:

cd ~/work/some-repo
git commit -m "Fix bug"
Enter fullscreen mode Exit fullscreen mode

Before the operation completes, gh-account-guard checks:

  • Current directory
  • Expected GitHub account
  • Active Git identity

If everything matches → nothing happens.
If something doesn’t → it blocks the operation or switches accounts automatically.

No prompts. No guessing.


Checking status

You can always see what account is active:

gh account-guard status
Enter fullscreen mode Exit fullscreen mode

This makes behavior explicit and easy to debug.


Why a GitHub CLI extension?

I wanted something that:

  • Works across all repositories
  • Doesn’t require repo-specific hooks
  • Is visible and inspectable
  • Fits into existing workflows

The GitHub CLI was a natural home for this.


What daily usage feels like

I’ve been using gh-account-guard daily for a few weeks across work and personal projects.

After setup, it fades into the background — which is exactly the goal.
No wrong commits. No cleanup. No mental overhead.


Who this is for

This is useful if you:

  • Use multiple GitHub accounts
  • Switch between personal and work repos
  • Contribute to OSS and private code
  • Want safety without friction

If you only use one account, you probably don’t need it.


Open source

The project is open source:

👉 https://github.com/adriandarian/gh-account-guard

If it saves you from one bad commit, it did its job.

Top comments (0)