Skip to content

A fun and interactive terminal tool for quickly switching between Git SSH keys on Unix systems.

License

Notifications You must be signed in to change notification settings

alexlobaza/git-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔑 git-switch

A fun and interactive terminal tool for quickly switching between Git SSH keys on Unix systems.

Version License Bash

✨ Features

  • 🎮 Interactive menu mode - navigate with arrow keys, no typing needed!
  • 🎨 Beautiful terminal UI - colorful interface with emojis and visual feedback
  • 🔄 Easy key switching - switch between SSH keys instantly
  • 🏷️ Alias support - create memorable aliases for your keys (e.g., "work", "personal")
  • 🔑 Key creation wizard - guided setup for creating new SSH keys
  • 📋 Key overview - see all available keys with their fingerprints and aliases
  • Fast and lightweight - pure bash, no dependencies
  • 🔒 Automatic configuration - updates SSH config for GitHub, GitLab, and Bitbucket
  • 🔙 Backwards compatible - supports both interactive and CLI modes
  • 🍎 macOS compatible - works with Bash 3.2+ (default on macOS)

📦 Installation

Homebrew (macOS/Linux)

Coming soon

Manual Installation

# Download the script
curl -O https://raw.githubusercontent.com/YOUR_USERNAME/git-switch/main/git-switch

# Make it executable
chmod +x git-switch

# Move to your PATH
sudo mv git-switch /usr/local/bin/

# Or for user-only installation:
mkdir -p ~/.local/bin
mv git-switch ~/.local/bin/
# Add ~/.local/bin to your PATH if not already there

Using the Install Script

curl -O https://raw.githubusercontent.com/YOUR_USERNAME/git-switch/main/install.sh
chmod +x install.sh
./install.sh

🚀 Quick Start

Interactive Mode (Recommended!)

Simply run:

git-switch

You'll see a beautiful menu:

╔══════════════════════════════════════╗
║          🔑  GIT-SWITCH 🔑           ║
║       SSH Key Switcher for Git       ║
╚══════════════════════════════════════╝

Current key: id_personal_ed25519

What would you like to do?

  ▶ Switch SSH Key
    Create Alias
    Create New Key
    Exit

Use ↑/↓ arrows to navigate, Enter to select, q to quit

Navigation:

  • / - Move selection up/down
  • Enter - Select option
  • Esc or b - Go back to previous menu
  • q - Quit anytime

📖 Usage Guide

1. Switch SSH Key

From the main menu, select "Switch SSH Key" to see all your keys:

Select a key to switch to:

  ★ id_personal_ed25519 (personal)
  ▶ id_work_ed25519 (work)
    id_client_rsa (client)

↑/↓: Navigate | Enter: Select | Esc/b: Back
  • Keys marked with are currently active
  • Aliases shown in parentheses (yellow text)
  • Navigate with arrow keys and press Enter to switch

2. Create Alias

Give your keys memorable names:

  1. Select "Create Alias" from main menu
  2. Choose a key from the list
  3. Enter an alias name (e.g., "work", "personal", "client-acme")

Now you can quickly switch using: git-switch work

3. Create New Key

The wizard guides you through creating a new SSH key:

  1. Select "Create New Key" from main menu
  2. Choose key type:
    • ed25519 (recommended) - Modern, secure, fast
    • RSA 4096 - Traditional, widely compatible
  3. Enter a name for your key (e.g., "work", "personal")
  4. Enter your email address
  5. Set a passphrase (recommended for security)

The wizard will:

  • ✅ Create the key with proper settings
  • ✅ Display your public key
  • ✅ Show where to add it (GitHub, GitLab, Bitbucket)
  • ✅ Offer to switch to it immediately

Example output:

✓ Key created successfully!

Key details:
  Private key: ~/.ssh/id_work_ed25519
  Public key:  ~/.ssh/id_work_ed25519.pub

Your public key (add this to GitHub/GitLab/Bitbucket):
────────────────────────────────────────
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... you@example.com
────────────────────────────────────────

Next steps:
  1. Copy the public key above
  2. Add it to your Git hosting service:
     • GitHub: Settings → SSH and GPG keys → New SSH key
     • GitLab: Preferences → SSH Keys
     • Bitbucket: Personal settings → SSH keys

Would you like to switch to this key now? [Y/n]:

💻 Command Line Mode

For quick operations without entering interactive mode:

List all keys

git-switch list

Switch to a key

git-switch id_ed25519
# or using an alias
git-switch work

Create an alias

git-switch alias work id_work_ed25519
git-switch alias personal id_personal_rsa

Remove an alias

git-switch unalias work

Show help

git-switch help

🎯 Real-World Examples

Freelancer with Multiple Clients

# Interactive mode: Create keys and aliases
$ git-switch

# Create keys for each client
→ Create New Key
   Name: client-acme
   Email: you@acme-corp.com

# Create aliases
→ Create Alias
   Key: id_client-acme_ed25519
   Alias: acme

# Quick switching from CLI
$ git-switch acme
✓ Switched to key: id_client-acme_ed25519

$ git clone git@github.com:acme-corp/project.git
# Uses the correct SSH key automatically!

Developer with Work and Personal Accounts

# Set up your keys once
$ git-switch alias work id_work_ed25519
$ git-switch alias personal id_personal_ed25519

# Morning: Switch to work
$ git-switch work
✓ Switched to key: id_work_ed25519

# Work on company repos
$ git clone git@github.com:company/backend.git

# Evening: Switch to personal
$ git-switch personal
✓ Switched to key: id_personal_ed25519

# Work on personal projects
$ git clone git@github.com:myusername/side-project.git

Team Onboarding

# New team member doesn't have SSH keys yet
$ git-switch

# Walk through the wizard
→ Create New Key
   Type: ed25519 [recommended]
   Name: work
   Email: newdev@company.com

# Key is created, public key shown
# Copy/paste to GitHub
# Ready to clone repos!

✓ Switched to key: id_work_ed25519

🔧 How It Works

git-switch works by updating your SSH configuration file (~/.ssh/config) to specify which key should be used for Git operations. It automatically configures:

  • GitHub (github.com)
  • GitLab (gitlab.com)
  • Bitbucket (bitbucket.org)

Configuration Storage

  • Aliases: Stored in ~/.ssh/git-switch-config
  • SSH Config: Modified in ~/.ssh/config (backups created as ~/.ssh/config.backup)

What Gets Modified

When you switch keys, git-switch adds/updates entries in your SSH config:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_work_ed25519
    IdentitiesOnly yes

This tells SSH which key to use when connecting to Git hosts.

🛠️ Requirements

  • Unix-like operating system (Linux, macOS, BSD, WSL)
  • Bash 3.2 or later (default on macOS and most Linux distros)
  • SSH keys in ~/.ssh directory
  • ssh-keygen (usually pre-installed)

❓ Troubleshooting

"No SSH keys found"

Make sure you have SSH keys in ~/.ssh/. Create one with:

ssh-keygen -t ed25519 -C "your_email@example.com"

Or use the built-in key creation wizard: git-switch → Create New Key

"Permission denied" when cloning

  1. Make sure your public key is added to your Git hosting service
  2. Test the connection: ssh -T git@github.com
  3. Verify the correct key is active: git-switch list

"Command not found"

Ensure the installation directory is in your PATH:

echo $PATH

If ~/.local/bin isn't listed, add to ~/.bashrc or ~/.zshrc:

export PATH="$PATH:$HOME/.local/bin"

Arrow keys not working

If arrow keys don't work in interactive mode:

  1. Make sure you're in a proper terminal (not piped input)
  2. Try using git-switch list for non-interactive mode
  3. Check that your terminal supports ANSI escape sequences

Keys exist but aren't showing up

Ensure your keys follow the standard naming convention:

  • Private key: ~/.ssh/id_keyname
  • Public key: ~/.ssh/id_keyname.pub

Or any name with a .pub extension for the public key.

🎨 Customization

Changing Default Git Hosts

Edit the update_ssh_config() function in the script to add or remove Git hosts.

Different Key Directory

By default, git-switch looks in ~/.ssh. To use a different directory, modify the SSH_DIR variable in the script.

📝 Contributing

Contributions are welcome! Here's how you can help:

  1. Report bugs - Open an issue describing the problem
  2. Suggest features - Share your ideas for improvements
  3. Submit PRs - Fix bugs or add features
  4. Improve docs - Help make the documentation clearer

📜 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

Created for developers who juggle multiple Git accounts and want a simple, beautiful way to manage their SSH keys.

🔗 Links

⭐ Show Your Support

If you find this tool useful, please consider:

  • ⭐ Starring the repo on GitHub
  • 🐛 Reporting bugs or requesting features
  • 📢 Sharing it with others who might find it useful
  • 💬 Letting me know how you're using it!

Made with ❤️ for developers who work with multiple Git accounts

About

A fun and interactive terminal tool for quickly switching between Git SSH keys on Unix systems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages