Link Sourcetree to your GitHub account

One of the most popular places to store and share your code online is GitHub. And one of the best free desktop Version control tools is without any doubt Sourcetree. Having all the good feature, of using them both, in mind, there are still some moments that can ruin your experience, especially when you are linking them together for the first time.


So here is my setup:

  • A GitHub account with some Public repositories and some Private repositories. As a general, you would not have much trouble with the public ones. I will focus on using a Private one in this blog post.
  • A Macbook machine (probably not any different on Windows, I will tell you next month when I go through the same steps on my new laptop).
  • A local installation of Sourcetree – version 4.0.2 (236), with embedded Git, version 2.27.0

What is the issue:

When you do the initial setup of Sourcetree, you enter your GitHub account, a browser window opens automatically, you are logged into your GitHub account and grant access for Sourcetree. Then the account setup is done and you can see it in Sourcetree > Preferences > Accounts. You can see thaht the Auth Type is set to OAuth by default.

With this setup in place however, you can’t clone your Private repository, if you already have it in place – you cannot pull from it, and you also can’t push any changes.

How did I resolve it:

Now to the best part – resolving the issue.
I spent some time reading the Atlassian forums (Sourcetree is an Atlassian product) and found a whole bunch of people dealing with the same problem. The problem seemed to be in the way the account is linked in Sourcetree.

The steps to fix it are the following:

  • Go to your GitHub account
  • Go to Account settings > Developer Settings
  • Go to Personal Account Settings and create a new token, using the “Generate new token” button
  • Give the permissions you would like Sourcetree to have, but make sure repo is checked (with all the sub-menus)
  • Then copy the newly generated token as you make sure to use the Copy button on the right (as you might copy some space character if you do it manually)
  • Now go back to the Accounts section in Sourcetree
  • Edit your account – change Auth Type from OAuth to Basic and enter the token from the previous steps into the Password field. Protocol should be left HTTPS

Voila – you can now clone, pull and commit into your Private GitHub repository, using Sourcetree.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s