I finally got around to setting up two-factor authentication on my Github account. The process went quite smoothly, until I started to play around with SourceTree and I found out that I was unable to push commits to a git repo.
SourceTree error
The error message that I was receiving seemed pretty generic at the time. Besides I knew I was typing my Github password correctly, so that could not be the issue. In hindsight not realizing the two-factor authentication (2fa) was the problem immediately was pretty stupid. The solution to this error is to login with a One Time Password (OTP) token not your normal Github password. If you do use the wrong password you will receive the follow error message.
Info
Note: If you use the official GitHub app you will not run into a login error because their app uses the GitHub API for authentication.
Luckily Github has made creating a OTP quite easy once you know what you are looking for. It is recommended practice to use one token per application. This means if I ever need to reject a token it will only effect the one version of SourceTree on one device.
Below are the steps needed to create your OTP token and re-add your Github account in SourceTree.
Setting up the OTP
To create the OTP, use the following link. Click on “Generate New Token”.
Give your OTP a Token description. Make sure at least the “repo” and “public_repo” options are checked. Click “Generate token”.
Configuration for SourceTree
If you already have SourceTree setup, you will need to edit your account password for GitHub. You can accomplish this by opening the Bookmarks window and clicking on the “Hosted Repositories” button.
Now you need to click on “Edit Accounts…” so you can select your Github account and make modifications.
Click on “Set Password”.
In the Authenticate window make sure and use your newly generated OTP token as your password. I recommend saving the password in your keychain.
Articles: atlassian KB, Ryan Sechrest