
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Easy GitHub account switching - manage multiple GitHub accounts with seamless context switching for Git config, SSH keys, and GitHub CLI
A command-line tool for managing multiple GitHub accounts on the same machine. Seamlessly switch between different Git configurations, SSH keys, and GitHub CLI authentication contexts.
Install globally via npm:
npm install -g ghswap
Get started in less than 2 minutes:
# 1. Install
npm install -g ghswap
# 2. Add your first account
ghswap add
# 3. Switch accounts anytime
ghswap work
ghswap personal
# 4. Clone and work normally
git clone git@github.com:username/repo.git
git commit -m "your changes"
git push
That's it! The tool handles:
Optional: Enable auto-switching based on directory:
ghswap setup # Add output to ~/.zshrc or ~/.bashrc
user.name and user.emailgh CLI when tokens are provided~/.ssh/configghswap # Interactive account selection menu
ghswap <account> # Switch to a specific account
ghswap add # Add a new account with guided setup
ghswap auto # Auto-detect account based on current directory
ghswap list # List all configured accounts
ghswap setup # Display shell hook setup instructions
ghswap ssh-config # Generate SSH configuration automatically
ghswap ssh-init # Check SSH keys and display generation commands
ghswap help # Display help information
ghswap --version # Show version number
When you run ghswap add, you'll be prompted for:
The tool will then:
$ ghswap add
Add New GitHub Account
Account name: work
Git username: John Doe
Git email: john@company.com
GitHub username: johndoe
Project directory: ~/projects/work
Setting up account...
Generating SSH key...
SSH key generated
Added to configuration
SSH config updated
Copy this SSH public key to GitHub:
────────────────────────────────────────────────────────
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... john@company.com
────────────────────────────────────────────────────────
Next steps:
1. Go to: https://github.com/settings/ssh/new
2. Title: "work - MacBook"
3. Paste the key above
4. Click "Add SSH key"
Test the connection:
ssh -T git@github.com
Auto-switch enabled for: ~/projects/work
Switch to this account and start working:
ghswap work
git clone git@github.com:johndoe/repo.git
# Work normally - ghswap has configured everything!
Configuration is stored in ~/.ghswap.json:
{
"accounts": [
{
"name": "personal",
"gitName": "John Doe",
"gitEmail": "john@personal.com",
"sshKey": "~/.ssh/id_rsa_personal",
"ghToken": "ghp_xxxxxxxxxxxx"
},
{
"name": "work",
"gitName": "John Doe",
"gitEmail": "john@company.com",
"sshKey": "~/.ssh/id_rsa_work"
}
],
"directoryMappings": {
"~/projects/personal": "personal",
"~/projects/work": "work"
},
"defaultAccount": "personal"
}
Generate SSH configuration entries for all accounts:
ghswap ssh-config
This command will:
~/.ssh/configThe generated SSH config uses host aliases:
# BEGIN GHSWAP MANAGED BLOCK
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes
# END GHSWAP MANAGED BLOCK
This approach is safe to run multiple times - only the managed block is replaced, preserving your other SSH configurations.
Check which SSH keys are missing:
ghswap ssh-init
Or generate keys manually:
ssh-keygen -t ed25519 -C "your@email.com" -f ~/.ssh/id_rsa_personal
ssh-keygen -t ed25519 -C "work@company.com" -f ~/.ssh/id_rsa_work
Add the public keys to their respective GitHub accounts:
cat ~/.ssh/id_rsa_personal.pub
cat ~/.ssh/id_rsa_work.pub
Simple Method (Recommended):
Just switch to your account first, then use normal GitHub URLs:
ghswap work
git clone git@github.com:username/repo.git
Advanced: Using Host Aliases (Optional)
If you prefer, you can use host aliases to specify the account in the clone URL:
git clone git@github.com-personal:username/repo.git
git clone git@github.com-work:username/repo.git
This is useful if you want to clone repos for multiple accounts without switching, but most users won't need this.
Switch accounts based on the current directory:
cd ~/projects/work
ghswap auto
For automatic switching when changing directories:
Generate the shell hook:
ghswap setup
Add the output to your shell configuration:
# For zsh
echo "$(ghswap setup)" >> ~/.zshrc
# For bash
echo "$(ghswap setup)" >> ~/.bashrc
Reload your shell:
source ~/.zshrc # or source ~/.bashrc
Now accounts will switch automatically:
cd ~/projects/personal # Automatically switches to personal account
cd ~/projects/work # Automatically switches to work account
Problem: SSH key not working
Solution:
# List currently loaded keys
ssh-add -l
# Manually add a key
ssh-add ~/.ssh/id_rsa_work
# Test the connection
ssh -T git@github.com-work
Problem: Git config not switching
Solutions:
git config --listProblem: Directory-based auto-switching not working
Solutions:
~ prefixsource ~/.zshrc~/.ghswap.json match your project pathsProblem: Permission denied when accessing SSH keys
Solution:
# Fix SSH key permissions
chmod 600 ~/.ssh/id_rsa_*
chmod 644 ~/.ssh/id_rsa_*.pub
gh authenticationProtect your configuration file:
echo ".ghswap.json" >> ~/.gitignore_global
Never commit tokens - The ghToken field is optional and should be used with caution
Use strong SSH keys - The tool generates ed25519 keys by default, which are secure and modern
Regular key rotation - Periodically update your SSH keys and remove old ones from GitHub
Issues and pull requests are welcome at github.com/shubhamV123/ghswap.
MIT License - see LICENSE file for details.
Shubham Verma
FAQs
Easy GitHub account switching - manage multiple GitHub accounts with seamless context switching for Git config, SSH keys, and GitHub CLI
We found that ghswap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.