Managing multiple Git repositories with different SSH keys can be a real pain, especially if you have multiple GitHub, GitLab, or Bitbucket accounts. Editing your ~/.ssh/config file or messing with repository settings is a drag and can lead to errors. But there’s a solution: gitsm! This awesome tool is cross-platform and makes SSH key management for Git a breeze. So you can focus on writing code, not worrying about configuration.
What is gitsm?
gitsm (Git SSH Key Manager) is an open-source CLI utility that simplifies SSH key management for Git repositories. It automates the tedious parts of SSH key setup and switching, making it suitable for freelancers, developers with multiple accounts, and teams with strict security policies.
Why Developers Love gitsm
- Automatic SSH Key Detection: Instantly finds all your SSH keys in
~/.ssh
. - Per-Repository Key Assignment: Each repo can use a different SSH key, no more global config hacks.
- Interactive Cloning: Choose the right SSH key when cloning, and gitsm configures it for you.
- Cross-Platform: Works on Windows, macOS, and Linux.
- No More Manual Edits: Forget about editing
~/.ssh/config
or.git/config
by hand. - Repository Management: Easily list, fix, or convert repositories to use gitsm.
- Security: Built-in SSH key validation and testing.
1. Installation
Install gitsm globally with npm:
npm install -g gitsm
Prerequisites:
- Node.js v16.x or higher
- Git installed and in your system PATH
- SSH keys in your
~/.ssh
directory
2. Clone a Repository with SSH Key Selection
Instead of using git clone
, simply run:
gitsm clone git@github.com:username/repo.git
- gitsm will prompt you to select an SSH key from your available keys.
- The repository is cloned and configured to always use your chosen key for all Git operations.
3. Day-to-Day Usage
After cloning, use Git as usual:
cd repo
git pull
git push
gitsm ensures the correct SSH key is used behind the scenes.
4. Manage Your SSH Keys and Repositories
- List SSH Keys:
gitsm list keys
- List Managed Repos:
gitsm list repos
- Fix a Repo’s SSH Config:
gitsm fix /path/to/your/repo
- Convert Existing Repo:
gitsm convert ~/projects/myrepo
Command Reference
Command | Description | Example |
---|---|---|
clone | Clone with SSH key selection | gitsm clone git@github.com:user/repo.git |
switch | Switch branches safely with stash handling | gitsm switch feature-branch |
convert | Convert repo to use gitsm | gitsm convert ~/projects/myrepo |
list keys | Show available SSH keys | gitsm list keys |
list repos | Show gitsm-managed repositories | gitsm list repos |
fix | Repair SSH configuration | gitsm fix ~/projects/myrepo |
upgrade | Update gitsm to latest version | gitsm upgrade |
help | Show command help | gitsm help switch |
Real-World Benefits
- No More SSH Key Conflicts: Perfect for developers with multiple Git accounts.
- Easy Onboarding: New team members can get set up in minutes.
- Portable and Secure: Your SSH key usage is always explicit and traceable.
- Time-Saving: Focus on coding, not configuration.
Final Thoughts
Tired of the hassle of SSH keys? Gitsm is here to save the day! With its clever automation, powerful features, and support for different platforms, managing multiple Git identities is a breeze. Install it now and enjoy hassle-free Git SSH key management.