This is a short follow up to my previous post,
on how to setup an environment so that you can connect to GitHub or
BitBucket on the same machine using different user accounts.
A few people have asked how they can create multiple user on one
machine that point to the same host e.g. BitBucket.org
Well, you will be pleased to know it is really simple!
You need to follow the same steps as my previous post, apart
from some small changes in the Config file.
So you need to:
- Create a new SSH key pair remembering to give each key pair
- Add the SSH Key to your BitBucket account
- Add the SSH Key to the SSH Agent
And now for the Config file!
I will assume that you have created one SSH Key pair called
id_rsa_work and one SSH Key pair called
id_rsa_personal and both of these accounts
are held on BitBucket.
Last time we used the config file to ensure that Git used the
correct Key file depending on whether we were connecting to GitHub
or BitBucket. We will do pretty much the same here but we will
assign different Host names so that Git knows which Key file to
# Work user account for BitBucket
# Personal user account for BitBucket
See how we have used change the Host value to
bitbucket-personal, it works pretty much the same
as changing the hosts file on your PC.
So now if we wanted to clone a Git repo from BitBucket using our
Work account we use this:
git clone firstname.lastname@example.org:MY_WORK_USER_NAME/MY_WORK_REPO_NAME.git
And now, I want to clone a repo from my personal BitBucket
git clone git@bitbucket-personal:MY_PERSONAL_USER_NAME/MY_PERSONAL_REPO_NAME.git
All you need to do is change the host from
bitbucket-personal - Git will work out which key
file to use.
Note: This approach will also work for GitHub.