- Generate 2 ssh keys with the command - ssh-keygen -t rsa. In my case, I generated two files with the names id_rsa and id_rsa_art.
- Copy and paste your public keys to bitbucket - https://bitbucket.org/account/settings/ssh-keys/.
- cat ~/.ssh/id_rsa.pub | pbcopy
- cat ~/.ssh/id_rsa_art.pub | pbcopy
- Now, let's config our switching logic. Go to ~/.ssh folder and create their file config with the command - touch config
- Open the config file in any text editor and put the instructions below
Host main-bucket
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
Host art-bucket
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_art
We've created 2 configs for bitbucket.org with aliases main-bucket and art-bucket.
- Now we can clone our project by replacing bitbucket.org with the respective alias. For example:
- git clone [email protected]:ken2ki/art_project.git -> git clone git@main-bucket:ken2ki/art_project.git
- If you already cloned your project, just set the URL with the respective alias as the origin:
- git remote add origin git@main-bucket:ken2ki/art_project.git - this would add to list of URLs
- git remote set-url origin git@main-bucket:ken2ki/art_project.git - this would set as origin URL
- Test it with any git push/pull/fetch/merge/rebase commands