Multiple Git Accounts on Same Computer
There are multiple source control Software-as-a-service(SaaS) services — GitHub, GitLab, or Bitbucket. Each organization or project chooses the service based on their needs or personal preferences.
As a developer, It is not very uncommon to land in a situation where you have to work on projects from different source control using the same machine. For example, GitHub is being used at work, but the open-source project your team is contributing is on GitLab. I had the same situation where I had to use my Mac with GitHub and Bitbucket account simultaneously.
This guide is for the Mac, but one can also use the exact instructions for other operating systems. Git uses Public-key cryptography for authentication, and account keys are stored in the .ssh
folder. There can be two ways: either use the existing keys or generate the new keys. For this guide, we will generate the new set of keys for both Bitbucket and Github.
Creating the SSH Keys
First, we will generate a new pair of public and private keys for my Bitbucket account and store them with the default settings.
ssh-keygen -t ras -C "email-address"
It will generate private and public keys (.pub), which are stored in .ssh
. Next, we will copy the public key and upload it to the bitbucket account.
pbcopy < ~/.ssh/id_rsa.pub
On the Bitbucket profile page, go to SSH keys, select add key and paste the copied…