git-ssh-switch is a CLI tool for managing multiple GitHub accounts with different SSH keys. It automatically selects the right key when cloning repos and updates local Git user info for each account.
- Node >= 18
First, if you want to use multiple Git accounts, you need to create multiple pairs of different SSH public and private keys. You can refer to the GitHub documentation to create them and configure SSH in GitHub.
Read the document here:
npm install -g git-ssh-switchBefore executing any command, the program runs a pre-check that creates a config.json file (~/.gss/config.json) for storing user information, backs up the existing SSH configuration file, and creates a new empty SSH config file (~/.ssh/config) for adding Host entries.
If everything is fine, you will see the message Pre-checks passed. in the console.
gits addgits listRun ssh -T for every account's host.
gits testClone a repository (allowing additional parameters identical to the git command), select an account, automatically replace the repository URL with the chosen account’s SSH Host, and update the local Git user information in the cloned repository after completion.
gits clone <repository> [<directory>]When adding an origin to an existing local repository, you can choose which user to use.The program will remove the existing remote origin (if it exists) and add a new one with the selected account's SSH Host. It also updates the local Git user information in the repository.
gits remote <repository>Set the Git user information for the current local repository by selecting the desired account.
gits localgits removeDelete all files created by git-ssh-switch and restore the latest backup of the SSH config file (if it exists).
gits reset