github-switcher
v0.1.3
Published
Manage multiple GitHub accounts on the same machine via SSH and git config.
Maintainers
Readme
github-switcher
Manage multiple GitHub accounts on the same machine via SSH and git config. Provides both an interactive CLI and explicit commands to add, list, delete, and switch accounts.
Installation
- Run via npx (recommended):
npx github-switcher- Or install globally:
npm install -g github-switcher
github-switcherUsage
- Interactive mode (no subcommand):
npx github-switcherThis opens an Inquirer-based menu to:
- List accounts
- Add account
- Switch account
- Delete account
When adding an account interactively, you can choose to log in with GitHub in your browser. The CLI will:
Start a GitHub device authorization flow.
Ask you to open a GitHub URL and enter a short code.
Automatically fetch your GitHub username and primary email and pre-fill them for the new account.
Add an account:
npx github-switcher add \
--id work \
--username your-github-username \
--email [email protected] \
--label "Work" \
--ssh-key-path ~/.ssh/id_github-work- List accounts:
npx github-switcher list- Delete an account:
npx github-switcher delete work --remove-key- Switch account (updates git identity):
npx github-switcher switch workWhen switching:
git config --global user.nameandgit config --global user.emailare updated.- If you run the command inside a git repository, the local repo config (
git config user.name/user.email) is also updated.
SSH configuration
For each account, github-switcher:
- Ensures
~/.sshexists. - Generates an SSH keypair (by default
~/.ssh/id_github-<id>). - Manages a dedicated block in
~/.ssh/configbetween:# github-switcher account: <id># github-switcher end
Each account gets a host alias like:
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_github-workUse this alias in your git remotes, for example:
git remote add origin git@github-work:your-github-username/your-repo.gitAccount storage
Accounts are stored globally in:
~/.github-switcher/accounts.jsonThis file tracks:
- All configured accounts
- The current active account id
- Timestamps for creation and updates
Notes
- The CLI expects
gitandssh-keygento be available on your PATH. - Node.js 18 or newer is recommended.
- The GitHub browser login flow works out of the box - no configuration needed.
