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:
[email protected] - SSH Key:
~/.ssh/id_rsa_github
- Email:
-
Bitbucket
- Email:
[email protected] - SSH Key:
~/.ssh/id_rsa_bitbucket - Repository:
vinhost/vh-ecommerce
- Email:
# GitHub
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_github
# Bitbucket
ssh-keygen -t rsa -b 4096 -C "[email protected]" -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 [email protected]:your-username/your-github-repo.gitBitbucket Example
git clone [email protected]:vinhost/ecommerce.gitSet identity info for each repo:
# Inside GitHub repo
git config user.name "Your Name"
git config user.email "[email protected]"
# Inside Bitbucket repo
git config user.name "Your Name"
git config user.email "[email protected]"To test which key is being used:
ssh -T [email protected]
ssh -T [email protected]