github-switch
v1.0.1
Published
Switch effortlessly between multiple GitHub and Git accounts with automatic Windows Credential Manager caching.
Maintainers
Readme
GitSwitch (github-switch)
Effortlessly manage and switch between multiple GitHub and Git accounts from your terminal with a single command — including automatic Windows Credential Manager caching & switching.
Features
- Multi-Account Git Config: Switch
git config user.nameanduser.emailinstantly. - Windows Credential Manager Integration:
- Automatically captures and caches active GitHub tokens before switching.
- Executes
cmdkey /delete:LegacyGeneric:target=git:https://github.comso git won't reuse the old account. - Automatically restores the target account's cached token into Windows Credential Manager so you can
git push/git pullwithout re-authenticating every time.
- Exact Syntax Match: Supports
-uname,-uemail,-token, as well as standard GNU flags. - Interactive Terminal UI: Run
github switchwithout arguments for an interactive picker. - Security-First: Tokens are stored privately in
~/.gitswitch/credentials.jsonwith restricted permissions and masked in CLI outputs. - Command Aliases: Registered under
github,gitswitch,git-switch, andgithub-switch.
Installation
npm install -g github-switchOr clone and link locally:
cd c:\Projects\github-switch
npm install
npm linkHow Credential Caching & Switching Works
When you push or pull over HTTPS, Git Credential Manager stores your GitHub login in Windows Credential Manager under:
Target: LegacyGeneric:target=git:https://github.comWhen you switch between accounts with GitSwitch:
Account A (active in Windows Credential Manager)
│
▼ [Run: github switch "Account B"]
1. Reads and safely caches Account A's token/credential in GitSwitch
2. Executes: cmdkey /delete:LegacyGeneric:target=git:https://github.com
3. Updates: git config --global user.name "Account B"
4. Updates: git config --global user.email "[email protected]"
5. Takes Account B's cached token and restores it into Windows Credential Manager!
│
▼
Account B is now active for both git commits AND git push/pull!When you switch back to Account A (github switch "Account A"):
- Account B's token is saved to cache.
- Windows Credential Manager is cleared.
- Account A's token is restored back into Windows Credential Manager.
CLI Commands
1. View all saved accounts
github list
# alias: github lsDisplays registered accounts, git status, and whether credentials are cached:
Registered GitHub Accounts:
┌──────────────┬───────────────┬───────────────────┬─────────────┬─────────┬──────────────┐
│ Status │ Username │ Email │ Credentials │ SSH Key │ Added / Used │
├──────────────┼───────────────┼───────────────────┼─────────────┼─────────┼──────────────┤
│ Active │ bytecamp-in │ [email protected] │ Cached │ none │ used today │
├──────────────┼───────────────┼───────────────────┼─────────────┼─────────┼──────────────┤
│ - │ personal-dev │ [email protected] │ Cached │ none │ added 9/11 │
└──────────────┴───────────────┴───────────────────┴─────────────┴─────────┴──────────────┘2. Add an account
# Add with username and email
github add -uname "username" -uemail "email"
# Add with token upfront
github add -uname "username" -uemail "email" -token "ghp_yourTokenHere"3. Switch active account (with credential swap)
github switch "username"
# or by email:
github switch "[email protected]"Output:
[info] Cached active credential for bytecamp-in
[info] Cleared Windows Credential Manager: cmdkey /delete:LegacyGeneric:target=git:https://github.com
[ok] Switched to GitHub account: personal-dev <[email protected]> [global]
[ok] Restored cached credentials for personal-dev into Windows Credential ManagerOptions:
github switch(interactive arrow-key selector)github switch "username" --local(switch only inside the current repository)github switch "username" --no-cred(skip modifying Windows Credential Manager)
4. Remove an account
github remove -uname "username"
github remove -uemail "email"Also removes any cached credentials for that account.
5. View current configuration status
github currentShows:
- Global and local repository
git config - Matching GitSwitch profile
- Active Windows Credential Manager entry for
git:https://github.com
6. Manage Windows Credential Manager & Tokens directly
GitSwitch provides the github cred command:
# Check Windows Credential Manager status & cached tokens
github cred status
# Explicitly save current Windows Credential Manager token to GitSwitch cache
github cred save
# Manually store or update a token for a user
github cred set <username> [token]
# Restore a cached user token into Windows Credential Manager
github cred restore <username>
# Clear GitHub entry from Windows Credential Manager
github cred clearTesting
npm testAll 21 unit and integration tests run via Vitest:
- Argument normalization (
-uname,-uemail,-token) - Configuration store
- Credential caching & masking
- CLI integration (switching, credential swapping,
cmdkeycommand calls)
License
MIT © 2026 GitSwitch Contributors
