CLI tool to manage multiple git identities and SSH keys
npm install git-identity-cli-toolA CLI tool to effortlessly manage multiple Git identities and SSH keys. Switch between work, personal, and other accounts with a single command.
- 🔑 Automatic Key Generation: Generates Ed25519 SSH keys automatically.
- ⚙️ SSH Config Management: Updates ~/.ssh/config with convenient aliases.
- 🔄 Context Switching: Sets local git user/email and updates remote URLs to match the correct SSH key alias.
- 📋 Easy Listing: View all configured identities.
bash
npm install -g git-identity-manager
`$3
1. Clone the repository:
`bash
git clone https://github.com/yourusername/git-identity.git
`
2. Install dependencies:
`bash
cd git-identity
npm install
`
3. Build and link:
`bash
npm run build
npm link
`Usage
$3
`bash
git-identity add
`
Follow the interactive prompts to create a new identity (e.g., 'work').
- Generates a new SSH key.
- Adds an alias to ~/.ssh/config (e.g., github.com-work).
- Copies the public key to your clipboard.$3
Navigate to your git repository and switch to the desired identity:
`bash
cd /path/to/repo
git-identity use work
`
This will:
- Set git config user.name and user.email for this repo.
- Update origin remote URL to use the github.com-work alias.$3
See which identity is currently active in your repository:
`bash
git-identity current
`$3
See all configured identities:
`bash
git-identity list
`How It Works
The tool uses SSH config aliases to manage multiple keys.
When you run
git-identity add, it creates an entry in ~/.ssh/config:`ssh
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes
`When you run
git-identity use work, it updates your repo's remote URL:
git@github.com:user/repo.git -> git@github.com-work:user/repo.git`This ensures the correct SSH key is always used for push/pull operations.