77

My organization is switching from Bitbucket to Github for project management. Today, I was trying to transfer our most recent project from Bitbucket to Github, by using SourceTree. I added a second remote repository to the project (using the URL of the destination repository on Github), brought everything up to date, and then attempted to push the code to the repository. A box popped up, asking for the password to my Github account. I entered in my (correct) password, and clicked 'OK', and the dialog box popped up again. I entered in my password (correctly) again, and it did the same thing.

My username is correctly identified, my password is correct, and I tried updating SourceTree because I had heard that it was an issue with a previous version. The problem persists.

I am using SourceTree 2.3.1

Abigail Fox
  • 1,623
  • 3
  • 16
  • 22

26 Answers26

110

If you are using two-factor authentication with GitHub you will need to create a personal access token and use it with SourceTree:

To work with GitHub's two-factor authentication in SourceTree you can simply use your access token instead of your password. The steps to do this are as follows:

  1. Go to your Personal Access Tokens settings in GitHub.
  2. Click on the Generate new token button.
  3. Name the token something descriptive.
  4. Select which scopes you wish to grant this token.
  5. Click the Generate token button.
  6. Copy the token and use it as a password in your hosted repositories.

You can find more information about this on GitHub's help here.

Mac Users: If your SourceTree keeps on asking for the password, go to the Terminal and type this:

git config --global credential.helper osxkeychain
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 8
    **Personal Access Tokens** is at **Settings** / **Developer settings** – Felix Nov 26 '17 at 02:54
  • 5
    "... and use it as a password in your hosted repositories". How? – Alex 75 Jun 22 '18 at 09:07
  • @Alex75, I'm not sure where the confusion is. Use the token instead of your password in SourceTree. – ChrisGPT was on strike Jun 22 '18 at 11:31
  • All this steps are done automatically by SourceTree when you clone a repo (A new token is automatically created and used). I still have this noisy GitHub login popup. So I want tot try your "manual" solution. In SourceTree, mrenu Repository -> Advanced -> User information tab. There is a checkbox for "Use global user settings" or you have to pass "Full name" abd "Email address". Where can I set the token ? This problem exists only for the private Git repository of my company (2 factor authentication enabled), I never had problems with my personal GitHub account at home. – Alex 75 Jun 23 '18 at 09:00
  • How can SourceTree generate a token for you if it can't log into GitHub? (If you're using 2FA and you want to log into GitHub you must either enter your password, be prompted for the 2FA code, and provide a valid one, or provide a personal access token. Did SourceTree ask you for a 2FA code?) – ChrisGPT was on strike Jun 23 '18 at 20:24
  • 15
    for me, this part did the trick: `git config --global credential.helper osxkeychain` – Lucho May 28 '19 at 11:40
  • 3
    I've been struggling with this for more than a year and never got to solving this problem. "git config --global credential.helper osxkeychain". This works like a charm! – Alex Dec 08 '19 at 21:12
  • 3
    One more step that I had to perform was - using `ssh -T git@github.com ` this prompted - ` The authenticity of host 'github.com' can't be established. RSA key fingerprint is _________. Are you sure you want to continue connecting (yes/no)? ` pressing `yes` after this made it work. – Ramandeep Singh Gosal Mar 08 '22 at 08:02
25

I am using a SSH key, but SourceTree was asking me a password every time.

Found on the community of Atlassian, this solution worked for me:

  1. Open the terminal, get into your project directory
  2. Type git config credential.helper store
  3. Type git pull
  4. Input username/password (if asked)

Voilà !

Marc
  • 11,341
  • 3
  • 27
  • 30
  • That is for https URLs. To my knowledge, an SSH URL does not involve a credential helper. – VonC Mar 27 '19 at 22:32
  • This helps! I';m using SSH too. – Glenn Posadas Feb 09 '20 at 16:39
  • I think it's good to mention, this solution stores your credentials unencrypted: https://git-scm.com/docs/git-credential-store – Jarosław Wiśniewski Nov 12 '21 at 15:49
  • this works after our enterprise stuffed AD service – WenChao Dec 06 '21 at 23:41
  • Only works for command line. Sourcetree keeps asking for the password EVERY TIME! I'm going crazy! – Pedro77 Oct 11 '22 at 15:12
  • This was the only solution that worked for me, after I tried with all of the above. It works with MacOS Ventura 13.0.1 & SourceTree 4.2.0 – donbuche Dec 13 '22 at 20:30
  • Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. – MGY Jul 13 '23 at 09:48
14

Follow to @Chris answer in case you've enabled 2FA, to use Personal Access Token in SourceTree, you need to add your acc with this token in SourceTree > Preferences with following information:

  • Auth Type: Basic
  • Username: {your-github-account}
  • Password: {your-personal-access-token}
  • Protocol: HTTPS

After that, you are able to clone your Github repo.

enter image description here

nahung89
  • 7,745
  • 3
  • 38
  • 40
10

A solution worked for me given by Andrew Magill, Copied from Source : link

The problem is that SourceTree's embedded Git client comes with git-credential-manager v1.12, which no longer works with Github since they disabled TLS 1.1 on their site. You need to get git-credential-manager v1.14. Easiest way to do that is to install a current copy of the Git client separately, and then switch SourceTree over to use that ("system git") instead of its embedded client. Alternatively, you can update git-credential-manager in your embedded client by replacing its files with the newest version from Microsoft.

A_01
  • 1,021
  • 11
  • 27
  • 1
    Thanks, this solution works for me. The key step was to update git credential manager here --> https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/tag/v1.14.0 – swdev Dec 13 '19 at 00:41
  • I just ran into this today with SourceTree Mac Client. GitHub just shutdown password authentication today. Pulled my hair out getting SourceTree to work. GitHub Desktop worked fine and Fork worked fine. SourceTree no go, until I finally thought to try switching SourceTree to use system git. @A_01 post helped confirm it. Thx. – mswlogo Aug 14 '21 at 02:51
  • 2
    This was by far the simplest solution that worked for me. – Godfather Apr 24 '22 at 06:53
8

I had a similar thing after an update; I tried re-adding my bitbucket credentials, changing the protocols, etc. with no luck, until...

  1. I opened my keychain and searched for bitbucket (probably the same for github, just search for github instead) under the Passwords category.

  2. I found that I had multiple Access Keys for my user, so I closed my repository, deleted all the keys of "application password" Kind, opened the SourceTree preferences > Accounts > removed my account and re-added it (login as usual - I used Basic with HTTPS).

  3. Keychain asks for permission to save the password, which I said yes and now I only see one key of the kind "application password".

I opened my repository from the repo browser and hey presto, no more password popups!

This bugged me for a whole week! If this helped you, you can do a little dance with me now :)

AEQ
  • 1,339
  • 1
  • 16
  • 20
  • Thank you ( ^_^) ! I have dropped all SouceTree keys and retry to pull, after entering password for 1st time it doesn't ask me for that anymore. It's much better than every time enter a password 2 times in a row even you've configured SSH keys – Pavlo Sadovyi Nov 11 '19 at 12:00
  • I thank You for that! Atlassian should definitely fix the issue with the saved passwords. They do not seam to understand, that passwords change! As well as I would hereby also recommend better explanations which passwords must be entered! There is no list for that in SourceTree and one must go and find that @£$€ themselves from users>yourname>local>Atlassian>password. – lohe Jul 30 '21 at 10:58
4

open terminal and clone your repo. repository url must have your usedid, For ex:

$ git clone https://<username>@github.com/<userId>/<reponame>.git
$ git clone https://mark@github.com/mak123/<reponame>.git

Then drag and drop the cloned folder into the sourceTree window.You can also do by clicking "+New Repository" button and from the menu by selecting "Add Existing Local Repository". It may ask for password again but this time it will get added to your keychain.

Prabhu.Somasundaram
  • 1,380
  • 10
  • 13
4

I finally was able to solve this after months of no luck. On a Mac :

  1. Open 'Keychain Access' on a Mac by using Launchpad or Spotlight Search
  2. Narrow down your search by selecting "login" under Keychains and "Passwords" under the Category (both filters on the left side of the window)
  3. In the top right hand corner of the window, do a search for "git"
  4. You'll likely see a keychain there. I right-clicked and deleted the one entry I had.
  5. Go into sourcetree and try to do a pull/fetch/anything. You'll be prompted for a password. This should re-initiate your password with Sourcetree. To double check this, go into your keychain and repeat steps 3 & 4. Click on the keychain and look at the access control tab. SourcetreeLogin should be listed as always having access now.

Keychain Example

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
bondra76
  • 99
  • 7
4

Here is what worked for me.

I tried almost all the solutions mentioned here and on the web a lot of times. I gave up multiple times before and was using it this way for more than a year I think. Finally, I was able to solve this annoying issue.

  1. As suggested by user "AEQ" in his answer, I deleted all the passwords related to GitHub from my Keychain Access.
  2. Tried deleting and re-adding the Github account. But still, the problem persisted. (generated a personal access token from "https://github.com/settings/tokens" and use it as the password)

What made it work was Make sure to use HTTPS and not SSH when adding the new user account. If you have already added the account, just edit it. That's it.

Finally, It feels good.

Attaching screenshots for ease.

Screenshot

2xSamurai
  • 1,221
  • 12
  • 18
3

In my case, the Sourcetree login screen repeatedly showed when pushing to GitHub. Logging in from that screen failed. I finally determined it was due to an expired OAuth token, which is trivial to fix.

  1. Navigate to the GitHub account config screen: Tools > Options > Authentication
  2. Click your GitHub account and then click edit
  3. On the Edit Hosting Account dialog click the Refresh OAuth Token button
Geck
  • 31
  • 3
  • "Edit" or "Add" - same deal - if the account is new to sourcetree, it's just as simple, since you just login via browser to do same, and it instantly recognises that. See my answer (written before I saw yours). – Engineer Jun 02 '21 at 21:03
  • Right, it just gets confusing if the OAuth token expires (which it does periodically). It's not obvious that that is what happened because the login screen appears and just fails to login. – Geck Jun 03 '21 at 01:34
2

This is what I discovered (after searching for 'sourcetree' in my drive C:):

  1. Uninstall SourceTree
  2. Delete folder C:\Users[username]\AppData\Local\Atlassian\SourceTree
  3. Delete folder C:\Users[username]\AppData\Local\SourceTree
  4. Reinstall SourceTree
jflaga
  • 4,610
  • 2
  • 24
  • 20
2

In addition to setting up the Personal Access Token on GitHub, and doing what A_01 states above, this may be helpful (it's how I finally got it working)

  • I made sure had the latest version of Sourcetree
  • I upgraded to the latest version of and used System Git (Tools -> Options -> Git)
  • Upgraded to the latest Git Credential Manager for Windows (this was via an installer I downloaded and double-clicked, very easy)
  • Ensured I was using OAuth for my GitHub account stored in Tools -> Options -> Authentication
  • Made sure I checked off the box "Allow Sourcetree to manage my credentials using the Git Credential Manager" (this was important!!) on Tools -> Options -> Git
  • Then when I triggered the GitHub dialog (via pushing a new branch, just an example), I logged in there (this is where it used to fail).
  • I next got the 2 factor auth dialog, and the code was sent to my phone as expected. I was able to enter the code from my phone into this dialog.
bcr
  • 1,983
  • 27
  • 30
2

In my case, I cloned the repo using HTTPS based url. Then I configured my githib account with 2-factor authentication using SSH key. So whenever I was pulling/pushing changes, it was showing me dialog to provide my password.

I fixed it by enabling SSH access by right clicking on project repo-menu on SourceTree.

enter image description here

Sauvik Dolui
  • 5,520
  • 3
  • 34
  • 44
2

Just another stupid reason: you may have changed credentials on your laptop, but there is another development PC running but not frequently used, that has SourceTree started and uses the old credentials frequently to poll status.

Sounds stupid, but took me some time to solve :-)

Stiefel
  • 2,677
  • 3
  • 31
  • 42
2

For windows user

change SSH Client from Putty/Plink to OpenSSH

in Tools -> Option -> SSHClient

enter image description here

Meghs Dhameliya
  • 2,406
  • 24
  • 29
1

If you are not using GitHub 2FA, another reason for asking you your password is:

Your GitHub repo url is an ssh one, not an https one.
Since git does not find your ssh keys (or your ssh key is not registered to your GitHub account), it fails back to account/password mechanism.

If you are using 2FA (and an https url), then you need a personal token as a password.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

SourceTree version 2.4.8.0

The problem for me seemed to be the order of setup between SourceTree and GitHub. I setup SourceTree first and just clicked all the "setup later" options.

An easy fix - Uninstall and re-install SourceTree. The non-obvious bit was needing to delete the actual program files manually.

From any "SourceTree.exe" shortcut, open file location. Mine forked at "C:\Users\myusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Atlassian" where the shortcut pointed to another shortcut.

Open that shortcut's file location. I eventually ended up at "C:\Users\myusername\AppData\Local\SourceTree". Delete the whole "SourceTree" folder. Go up one level to "...\Local" and delete the "Atlassian" folder as well.

Now uninstall SourceTree. Make sure your GitHub is setup the way you desire (for me, I also created and saved an SSH key that I used for SourceTree setup). Re-install SourceTree using all the correct credentials, point to the right repository and such.

After all this, SourceTree asked for my GitHub credentials twice, with two different dialog boxes, then stopped and worked! No more endless loop. Good luck!

Josh
  • 11
  • 2
1

Mac: This solution works for me. After clone code successfully, you open terminal and run this code

git config --global credential.helper osxkeychain
Anh Duy
  • 1,145
  • 15
  • 25
1

For future references, I solved this problem by changing the GIT system used in Sourcetree, from Embedded to System.

How to change the git system:
1. Find the Options submenu (located under Tools menu) and click on it to view the Options popup
2. On the Options setting popup, find the Git tab, then click on it to view the Git setting
3. Find Git version setting, then check the version used in it. In my case, I changed it to system because previously I'm using Git bash cmd, and it looks like that the git embedded in Sourcetree clashes with each other.
4. Restart Sourcetree

artikandri
  • 143
  • 2
  • 10
1

Since this question is specifically about SourceTree and Github, the answer in 2021 is simple. Quoting bcr:

Ensured I was using OAuth for my GitHub account stored in Tools -> Options -> Authentication

  • Go there. Select Add (new account).
  • Select OAuth.
  • Click Refresh OAuth Token. A browser page will open (github.com) requesting renewal of your token.
  • Login to accept. SourceTree will immediately respond by acknowledging the token provided by github.com.
Engineer
  • 8,529
  • 7
  • 65
  • 105
1

Really struggled with this on Mac, couldn't get it to work with SSH. Ended up following this guide which worked: https://www.youtube.com/watch?v=otRHRPnHDeI.

There were a couple things which could have been the cause, it may not have been the SSH itself. For instance, Oauth apparently doesn't work on SourceTree despite nothing appearing wrong immediately when using it. Making sure you use a Personal Access Token and not your real password among others.

A good rule of thumb is, if after connecting your account it only shows your public repos, it's already broken. https://github.com/settings/tokens

Theo
  • 45
  • 8
1

In my case I needed to put my ssh password instead of my personal access token. Then it worked.

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32765346) – abdo Salm Sep 26 '22 at 18:46
0

In my case, this was happening with a submodule that had defaulted to https even though the main project was using ssh. I fixed it by changing the submodule's repo path in SourceTree's Repository Settings to use the ssh path instead of https.

Swindler
  • 802
  • 10
  • 9
0

If you are using "Username & Password" authentication,you can try to change to use SSH keys for the authentication.

I have met this kind of situation when I commit to GitLab everytime.When I changed the way of authentication:SSH keys,the problem has been solved.

ifeegoo
  • 7,054
  • 3
  • 33
  • 38
0

In my case, the password that Sourcetree was asking for was for the ssh private key password. If I remove the password from the ssh key, this prompt doesn't come up.

However since I wanted the password to be there, I kept investigating why it wasn't accepting my ssh key password.

Turns out there is a wrinkle. If you have multiple ssh private keys which have different passwords, Sourcetree will give you a password prompt for each password.

Think of it this way - if you have a fresh shell in your system, and you just started ssh-agent up, and ran ssh-add, what are the password prompts that you get? For every such password prompt, Sourcetree will give you this dialog box. In fact, if you add passwords to the dialog in the same order as you would in the shell to an ssh-add, this would work. In fact, I am guessing Sourcetree is doing exactly the same in the background.

So my final solution was 1) keep the passwords on the ssh keys 2) make all these passwords the same. So now Sourcetree will give me a single password prompt, and entering the ssh private key password will work.

Sandip Bhattacharya
  • 1,042
  • 10
  • 11
0

The easiest way is to create an app password and use that password. Here you can see how you can create an app password on Bitbucket:

https://docs.snyk.io/tutorials/getting-started/atlassian-integrations/atlassian-bitbucket-app-password

Arash MAS
  • 128
  • 1
  • 7
-1

Go to Sourctree -> Tools -> Options -> Git Select

Omkar
  • 1
  • 1