This repository demonstrates how to configure and manage multiple Git accounts (GitHub and Bitbucket) on a single Windows machine using separate SSH keys and SSH host aliases.
-
GitHub
- Email:
abc@gmail.com - SSH Key:
~/.ssh/id_rsa_github
- Email:
-
Bitbucket
- Email:
xyz@vinhost.com - SSH Key:
~/.ssh/id_rsa_bitbucket - Repository:
vinhost/vh-ecommerce
- Email:
# GitHub
ssh-keygen -t rsa -b 4096 -C "abc@gmail.com" -f ~/.ssh/id_rsa_github
# Bitbucket
ssh-keygen -t rsa -b 4096 -C "xyz@vinhost.com" -f ~/.ssh/id_rsa_bitbucketeval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_bitbucket- Copy the public key:
clip < ~/.ssh/id_rsa_github.pub
- Then add it to GitHub SSH Settings
- Copy the public key:
clip < ~/.ssh/id_rsa_bitbucket.pub
- Then add it to Bitbucket SSH Settings
Create or edit ~/.ssh/config:
# GitHub
Host github.com-abc
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
# Bitbucket
Host bitbucket.org-xyz
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_bitbucket
GitHub Example
git clone git@github.com-abc:your-username/your-github-repo.gitBitbucket Example
git clone git@bitbucket.org-xyz:vinhost/ecommerce.gitSet identity info for each repo:
# Inside GitHub repo
git config user.name "Your Name"
git config user.email "abc@gmail.com"
# Inside Bitbucket repo
git config user.name "Your Name"
git config user.email "xyz@vinhost.com"To test which key is being used:
ssh -T git@bitbucket.org-xyz
ssh -T git@github.com-abc