Adding Multiple Github Accounts to Sourcetree

Adding Multiple Github Accounts to Sourcetree

I wanted to add multiple Github accounts to the Sourcetree software and it took me some time to figure it out.

Generating a new SSH key

The first step is to generate ssh keys1,

  1. Open Git Bash
  2. Paste the text below, substituting in your GitHub email address.
ssh-keygen -t ed25519 -C "[email protected]"

If you get asked for choosing the name for keys generated, choose an appropriate name like id_numeryst for the generated key. For the passphrase, use an appropriate passphrase or leave it empty if it does not concern you.

On Windows, on the path C:\Users\YourUsername\.ssh, you see the generated keys.

Adding your SSH key to the ssh-agent

Next, if you are on the Windows operating system, open up Git Bash then type the following

ssh-agent bash
ssh-add ~/.ssh/id_ed25519

id_ed25519 is the name you chose, we chose id_numeryst in the above scenario.

Adding a new SSH key to your Github account

To add a new SSH key to your Github account2, open up ~/.ssh/id_ed25519.pub and copy its content then

  1. In the “Access” section of the sidebar, click SSH and GPG keys.
  2. Click New SSH key or Add SSH key.
  3. In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal laptop, you might call this key “Personal laptop”.
  4. In the “Key” field, paste your public key.
  5. Click Add SSH key.

Setting up Github for SSH keys for Sourcetree

Open up Sourcetree, go to tools -> options, and in the general tab, go to SSH Client Configuration, click three dots (…) and browse to the ~/.ssh/id_ed25519 and select it. Open up Sourcetree, go to tools -> options, and in the general tab, go to SSH Client Configuration, near three dots (…), if you see any path like C:\Users\YourUsername\.ssh\id_numeryst delete it then click on ok button. Then go to tools->Add SSH Key... and go to the path C:\Users\YourUsername\.ssh\ and select the file id_ed25519 or in our case id_numeryst. Note that you do not select ~/.ssh/id_ed25519.pub but the one without .pub extension. ( In our scenario, you choose whatever you named your generated keys, like id_numeryst ). For adding additional SSH keys, go to Tools -> Add SSH Key. If you want to remove all the added SSH Keys go to tools -> options, and in the general tab, go to SSH Client Configuration and remove all the add key paths near the three dots (…).

In addition, in your Github repository, make sure you have chosen the appropriate user and email address that has access to that specific repository by going to settings -> advanced and uncheck the Use global user settings.

  1. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent[]
  2. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account[]
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments