Connecting Mac SourceTree with your GitHub account

The fastest way to get GitHub and SourceTree to play nice

TL;DR

  • Delete the Github authentication files under Home > Library > Application Support > Sourcetree
  • Restart SourceTree
  • Setup your GitHub Account using oAuth

It stopped working

Don’t you hate it when you’ve done some very nice programming that implemented that awesome new feature or fixed an annoying bug that caused a crash of your app?

Especially when it’s late, and you’re like: “let me just commit this version so I can go to bed sleeping like a rose as my code is committed and safe from harm”.

That dream was crushed as recently, I couldn’t commit from SourceTree to a GitHub repository I was working on after a sweet bug fixing session for a client’s app. 

Whatever I tried or did, Sourcetree kept on barking at me with a nice red commit failed error:

“Invalid username or password”

The credentials seemed to be done for. And I just couldn’t get them working quickly.

Cleaning up the password mess

If you are setting up a fresh connection from your SourceTree app with your GitHub account, and you never did this before on your current Mac, you can skip this chapter.

I tried removing my GitHub account under Preferences > Accounts, and using a Personal Access Token that I did setup under my Github account’s Token page.

Nade. Nope. Nothing. 

Then I tried reconnecting using a new oAuth account item.

Still no dice 🙈.

It seemed that whatever I did, the new credentials weren’t picked up.

Then it struck me ⚡️.

The Mac OS version of SourceTree saves authentication files on disk.
What if there were files remaining that messed up with my authentication setup?

The following steps assume you know what you’re doing and you don’t have a gazillion separate GitHub accounts on your machine to access various accounts / and or repos. If — like me — you have one GitHub Account and one pair of creds, you’re saving to… go on.

🧽 Here’s the steps on how to clean your authentication mess:

  1. Open Finder
  2. Go to the following location home directory > Library > Application Support > Sourcetree
    If you can’t see the Library subdirectory, turn on “view hidden files” using the following shortcut: Command, Shift and Period keys: cmd + shift + [.]
  3. You should see some files with formats like:
    – <yourusername>@STAuth-github.com OR
    – hwrakejhewrjhawekrearaejrhwkr-<yourusername>.github.com
    (possibly more variants visible)
  4. If you remove all the files that have “github” in it from the directory, you make sure that SourceTree won’t use those (wrong) authentication setups.
    Store them somewhere safe if you’re not sure they can be removed safely
  5. Important: restart SourceTree

Now you’ve cleaned up the “authentication attic” that the Sourcetree app has been stuffing.

Hook Up GitHub With SourceTree

This post isn’t about all the benefits and security aspects that come with using your GitHub account via HTTPS, SSL, Personal Access Tokens and what not.

If all you want is a safe and quick way to connect SourceTree with GitHub, follow the next steps:

  1. (re)start SourceTree
  2. Go to Preferences > Accounts
  3. click on Add…
  4. Select the following settings:
    Host: Github
    Auth Type: oAuth
    Protocol: HTTPS
  5. Click on “Connect Account”
  6. If not already done, login into your GitHub account
  7. In the dialog that says “Do you want to allow this page to open SourceTree?”, answer with “yes”
  8. You’re now back in SourceTree, and the app should show the connected account

You can now do al the GIT actions you desire from your happy little SourceTree interface.

Enjoy, and remember:

Code Hard, Ship Harder 🔥

This post is also published on Medium.