If you work across multiple Git accounts (personal, work, client projects, etc.), you normally have to deal with SSH host aliases or prefixes on every git command to use the right identity. git-switch lets you switch between accounts with a single command, it handles your SSH config and git user settings so you can just use git normally.
- Config-based account management via a simple pipe-separated file
- Automatic SSH config generation with
IdentitiesOnlyenforcement - Supports GitHub, Bitbucket, and GitLab
- Works immediately in the current terminal (no shell restart)
# Clone the repository
git clone https://github.com/KaleLetendre/git-switch.git
cd git-switch
# Run installer
./install.sh
# Add an account
git-switch -a
# Switch accounts
git-switchcurl -sSL https://raw.githubusercontent.com/KaleLetendre/git-switch/main/install.sh | bash- Clone this repository
- Copy
bin/git-switchto somewhere in your PATH (e.g.,~/.local/bin/) - Make it executable:
chmod +x ~/.local/bin/git-switch
Before adding an account, you need an SSH key for it. If you already have one, skip to step 3.
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_myaccount -C "your.email@example.com"cat ~/.ssh/id_ed25519_myaccount.pubCopy the output and add it to your provider:
- GitHub: SSH and GPG keys
- Bitbucket: SSH keys
- GitLab: SSH Keys
git-switch -aThis will prompt you for the account name, email, SSH key path, description, and hosts.
git-switchSelect an account from the menu, then use git normally:
1) Personal (Personal GitHub - john@example.com)
2) Work (Work Account - john@company.com)
Enter choice (1-2): 1
Accounts are stored in ~/.config/git-switch/accounts.conf. You can also edit this file directly:
# Format: name|email|ssh_key|description|hosts
Personal|john@example.com|~/.ssh/id_ed25519|Personal GitHub|github,bitbucket
Work|john@company.com|~/.ssh/id_ed25519_work|Work Account|github,gitlab
Fields:
- name: Account identifier (no spaces), shown in the menu
- email: Git commit email
- ssh_key: Path to SSH private key
- description: Shown next to the name in the menu
- hosts: Comma-separated:
github,bitbucket,gitlab
- Reads configuration from
~/.config/git-switch/accounts.conf - Generates SSH config with proper
IdentityFilemappings - Updates git config with selected account's name and email
- No shell restart needed - works immediately
- Handles config files without trailing newlines (common edge case)
- Extracts username from email if not explicitly provided
- Backs up original SSH config on first run
- Bash 4.0+
- Git
- SSH client
- Linux/macOS (WSL on Windows)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Kale Letendre - @KaleLetendre
⭐ If you find this tool useful, please star the repository!