You set your git user.email to your work address last Tuesday. Forgot to switch back. For the next three weeks every commit to your personal side project went out under your employer's email. You found out by accident, looking at your contribution graph.
Git has no idea you're two different people depending on which folder you're in. SSH cheerfully sends every key in your agent to every host. The GitHub CLI is logged into a different account than your last git config. None of these layers talk to each other, and any of them can silently disagree.
gitswitch makes them agree, and refuses to let you commit when they don't.
brew install target-ops/tap/gitswitchSingle binary. ~2 MB. macOS arm64/x64, Linux x64/arm64. No Python. No runtime dependencies. Installs in 8 seconds.
Windows: grab the .zip from releases.
gitswitch init # auto-detect what's already on this machine
gitswitch use work ~/work # bind work identity to a directory
gitswitch use personal ~/code # bind personal identity to another
gitswitch guard install # refuse wrong-author commits at the sourceThat's it. Every cd is now a switch. Forget to switch — gitswitch won't let you ship the bad commit.
| Command | What it does |
|---|---|
gitswitch init |
Auto-detect identities from your ~/.gitconfig, ~/.ssh/config, GitHub CLI, ssh keys |
gitswitch use <id> [<dir>] |
Bind an identity to a directory (writes a sentinel-marked includeIf block) |
gitswitch guard install |
Install the global pre-commit hook that blocks wrong-author commits |
gitswitch doctor |
Verify all layers — git, ssh, gh, signing — agree on who you are right now |
gitswitch why |
Explain, in plain English, why your active identity is what it is |
Run any command with --help for the full reference.
Manual includeIf |
gh auth switch |
gitswitch | |
|---|---|---|---|
| Auto-switch by directory | ✓ (if you nail the trailing-slash gotcha) | ✗ | ✓ |
| Per-account SSH key isolation | manual | ✗ | ✓ |
Keeps gh in lockstep with git |
✗ | partial | ✓ |
| SSH commit signing on by default | ✗ | ✗ | ✓ |
| Refuses wrong-author commits | ✗ | ✗ | ✓ |
| One-command verify all layers | ✗ | ✗ | gitswitch doctor |
Three things happen the first time you gitswitch use <id> <dir>:
-
Per-identity gitconfig at
~/.config/gitswitch/identities/<id>.gitconfig— setsuser.name,user.email, signing key, andcore.sshCommandwithIdentitiesOnly=yes. -
Conditional include — a sentinel-marked block in
~/.gitconfigthat loads the per-identity file only when you're inside the bound directory:# >>> gitswitch:work [includeIf "gitdir:~/work/"] path = ~/.config/gitswitch/identities/work.gitconfig # <<< gitswitch:work -
Binding record in
~/.config/gitswitch/config.jsonsogitswitch whycan explain itself later.
Once guard is installed, every git commit runs a ~5 ms check: does user.email match the identity bound to this directory? Yes → commit. No → refuse with a one-line fix. The dev.to story "I used the wrong git email for two weeks and no one noticed" — gitswitch makes that story impossible.
Git identity should be infrastructure, not something you remember.
The tool is small, the binary is single, the only state on your machine lives in ~/.config/gitswitch/ and the directories you tell it to manage. No service. No cloud sync of your keys. No telemetry. The maintainer is one developer who got bitten and built this; the issue tracker responds in days, not weeks; the roadmap is public; the tests pass.
- Issues — bugs and feature requests
- Discussions — questions, design conversations
- PRs welcome. Run
go build ./cmd/gitswitchand try the binary against your own setup before opening one.
MIT. See LICENSE.
