The pain point
There are multiple reasons why you might need to work in multiple Bitbucket accounts:
- You might have one account for work, and one for your own personal projects.
- You might be a freelancer with multiple clients, working in their own Bitbucket environments.
Whatever the reason, you will need to manage an SSH key for each Bitbucket account, and modifying your SSH config on every push/pull is not the answer!
The solution
Assuming you've already created your SSH keys in the normal way, all you need to do is modify your .ssh/config
file to look something like this:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
You need to replace id_rsa_bitbucket_work
and id_rsa_bitbucket_personal
with the names of your SSH keys.
To clone a repo with your newly configured keys, simply replace bitbucket.org
with either bitbucket-work
or bitbucket-personal
in the URL string. For example, to clone a repository in your work account:
git clone git@bitbucket.org:my-org/my-repo.git
will become
git clone git@bitbucket-work:my-org/my-repo.git
Specify the repository git user
The last thing to do is set the git user on a repo-by-repo basis in the normal way, depending on which account you've cloned the repo from, for example:
1 | |
2 | |
And that's it, now you can easily work in multiple Bitbucket accounts from the same device!