131

I'm trying to push my project via the https protocol on bitbucket using sourcetree.
But I can't connect to bitbucket with my login and password (which work on the website), I have a fatal error : "Authentication failed".

I read on other posts I can work around the problem using the ssh protocol instead of the https one, so I set up a ssh key following instructions on the source tree faq. But now I don't know how I can change to the ssh protocol when I want to push my code. Someone know how I can do this ? Thank you.

6
  • 16
    Change remote origin address from https ( ie: https://<username>@bitbucket.org/<username>/<repo>.git ) to ssh ( ie: git@bitbucket.org:<user>/<repo>.git ). You will find these addresses on the right side of your repository page. ( git remote set-url origin git@bitbucket.org:<user>/<repo>.git ) Jan 19, 2014 at 8:35
  • 1
    This should be marked as answer.
    – ronnyfm
    Mar 29, 2016 at 20:40
  • No solutions yet? (I am assuming by looking there is no accepted answer)
    – Talha
    Jan 11, 2017 at 8:54
  • Delete the default user names and saved passwords, It worked for me with a similar issue. Tools > Options > Authentication
    – NoamG
    Feb 28, 2017 at 14:42
  • This happened to me when the remote authentication server went down. If that's the case, nothing can be done about it aside from committing locally and being patient.
    – Cam
    Mar 23, 2017 at 20:14

34 Answers 34

146

If you got authentication issues with the GIT console, you can try to switch your configuration to HTTPS and specify user & password with the following command :

https://<username>:<password>@bitbucket.org/<username>/<repo>.git

But careful:

Coming back to this answer that I made a very long time ago, I want to give credits to @ChristopherPickslay for pointing out that the password is stored as clear text in the .git/config file.

If you want to roll with HTTPS, you can securely store your password with Git credential manager

But personnally, I now always use SSH authentification, as it seems to be a better practice, because you use a personal pair of public/private keys that will prevent your password to be stored outside. Apart from the fact you can put a passphrase on your key, and then you also need to store the password on a credential manager or ssh-agent.

11
  • 3
    Err... My answer wasn't random. As I'd the same problem and wanted to switch to SSH protocol, but you don't have to in order to make it work. Directly specify password can make the https auth method works. Just sayin'.
    – Alex
    Feb 11, 2014 at 21:18
  • 2
    I realize it's not random, but it does not answer the question. If you modify your answer to also address SSH authentication then I'd be happy to remove my downvote :)
    – Dan
    Feb 11, 2014 at 22:10
  • 20
    Undoing the down vote. This solved my problem. I didn't want an ssh solution. Stack overflow questions don't live in a vacuum. A useful answer is a useful answer.
    – funroll
    Feb 19, 2014 at 19:41
  • 12
    Also noting the specific command I used was git remote set-url origin https://<username>:<password>@bitbucket.org/<username>/<repo>.git.
    – funroll
    Feb 19, 2014 at 19:46
  • 25
    This puts your password in clear text in your .git/config file Mar 27, 2015 at 19:55
52

I recently had a similar issue with SourceTree: any time I tried to push/pull/fetch to/from the remote origin I would get an authentication error (using SourceTree with Stash). Sometimes I would be challenge in Stash with a CAPTCHA but it never made a difference if I provided the correct information or not.

For me, we're using SourceTree and Stash in a corporate environment; user accounts are based on network credentials. Part of our network security requires us to change those passwords on a regular basis.

I was operating under the assumption that SourceTree/Stash was "aware" of any change made to my network password. But apparently -- at least in this instance -- it was not.

To fix, all I needed to do was:

Tools > Options > Authentication > Edit (Edit Password)

I set the password to match my current network password and everything began working as expected.

Not sure if this helps the OP but I hope it may help someone else looking for answers to a similar issue.

4
  • I am using SourceTree + Bitbucket but not in a corporate environment (i.e. specific Bitbucket credentials) and changing the password via the suggested method worked. Thanks :) Dec 8, 2015 at 7:52
  • 9
    I can't find anything like 'Tools', 'Options', 'Authentication' or 'Edit password' on SourceTree.. I'm on a Mac though.
    – Sti
    Feb 8, 2017 at 9:55
  • 1
    @Sti Mac users need to go to Preferences under SourceTree menu (instead of Tools/Options menu). Apr 9, 2017 at 5:59
  • For Mac users: Go to SourceTree -> Preferences -> Accounts, select account, click Edit, then click Connect Account and login with your Atlassian account there. Mar 24, 2018 at 8:29
45

I tried everything else and found helpless but this indeed worked for me "To update your credentials, go to Control Panel -> Credential Manager -> Generic Credentials. Find the credentials related to your git account and edit them to use the updated passwords".

Above Solution found in this link: https://cmatskas.com/how-to-update-your-git-credentials-on-windows/

4
  • 7
    To be specific for Windows 10: Control Panel -> User Account -> Credential Manager -> Manage Windows Credentials Jul 13, 2020 at 15:17
  • Finally it is very basic solution and it's works !!! Thank you
    – ati ince
    Apr 12, 2021 at 14:16
  • It worked for me thanks, previously popup will come automatically to enter credentials but not came this time
    – Arpit Jain
    May 12, 2021 at 10:41
  • Normally it worked for me too before, but this time wasn't work. So I went to Generic Credential settings and delete my profile. Then went to the git command line and try again. Command-line trigger credential pop-up UI and filled again the same credential then worked! Just want to add more information for public benefit :)
    – ati ince
    Apr 29, 2022 at 10:42
30

Tools -> options -> git and selecting 'use system git' did the magic for me.

1
  • 5
    'SourceTree > Preferences > Git ' on OSX.
    – Tbadams
    Dec 8, 2017 at 17:26
18

Windows start up menu,Search for windows credential manager. Search for bitbucket url, Try updating password there.. and do git operation again. It should work.

2
  • This was the solution in my case. I'm running Windows-7 and had a recent password change. The cached credentials for the bitbucket server were out of date in Credentials Manager.
    – Brett
    Dec 17, 2019 at 11:32
  • True, Windows credential manager store passwords and details. Problem is due to cache. So always check for the password in credential manager. Sep 11, 2020 at 8:40
17

I solved the issue by editing the stored value in the OS X Keychain: I looked for "bitbucket" (as Application password) and changed the value.

Then on Sourcetree, when I tried to push, I directly had to re-enter my new password.

2
  • 2
    Deleting that keychain helped me because it caused source tree to ask for new password.
    – novomanish
    Jul 31, 2017 at 6:57
  • On MacOS 10.13 (High Sierra) it is very important to reboot the machine (or maybe at least logout/login) for this to work after you deleted the keychain entries. Otherwise the new password could not be stored in the keychain by Sourcetree and every git operation causes many password prompts.
    – Ernie
    Feb 18, 2020 at 17:17
13

Deleting the Sourcetree password cache file worked for me. Navigate to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree and delete (or rename) the file named passwd. Restart SourceTree and execute a command (e.g. Pull, Push, etc..) that requires authentication. SourceTree will then prompt you for your password, rewriting the cached credentials.

1
  • This has fixed the issue on several different occasions for me. Thanks!
    – Halee
    Feb 27 at 19:35
11

The issue was solved for me after changing the repository password, using no special characters (!"§$%&&).

Obviously, win-credential-store and git and bitbucket's web interface use different character encodings.

complete procedure:

D:\shared\Project> cd /path/to/your/project
D:\shared\Project> git init
D:\shared\Project> git remote add origin https://bitbucket.org/USERNAME/project.git
D:\shared\Project> git-credential-winstore.exe

then

D:\shared\Project> git push
Failed to erase credential: Element not found
fatal: Authentication failed for 'https://bitbucket.org/USERNAME/project.git/'

After changing the passphrase:

D:\shared\Project> git push
Counting objects: 102, done.
Delta compression using up to 8 threads.
... etc. ...

Settings in Windows tresory:

address: git:bitbucket.org (remeber the preceding "git:")
user: USERNAME
pass: old incl!"§§$%&, new without!"§$%%&/( (your passphrase!)
2
  • Similarly, I needed to change my username to something without an underscore in it. Apr 20, 2016 at 0:34
  • 1
    Wow. that is beyond criminally stupid. Looks like we know what all Atlasian bitbucket account passwords have no symbols in them. Ughhh.
    – deweydb
    Apr 23, 2016 at 2:46
7

Tools > Options > Use System Git , then select the git.exe file

enter image description here

The credentials will be required again, and the problem will be solved.

1
  • Can anyone can provide details as to why this works? Dec 5, 2018 at 14:39
7

After fighting with this for a long time, it looks like I found something that seems to work. I was optimizing the urls to not include the username (keep it as generic as possible), but the authentication dialog kept popping up:

enter image description here

I tried everything that came into mind, such as:

  1. Enable and disable MFA (Multi Factor Authentication)
  2. Create app passwords (again, with and without MFA enabled)

No matter what tools I used (including SourceTree), nothing worked. The server kept returning: "Create an app password"

Basically you must

  1. Use the url including the username (e.g. https://myusername@bitbucket.org/...)
  2. Use an app password created in bitbucket

Would be so nice if the server would have returned this in the response instead of suggesting to use an app password...

2
  • Thank you so much! This worked, i had to enter indeed in the popup not only my username but: myusername@bitbucket.org Nov 1, 2021 at 16:32
  • (Using Bitbucket) this was the solution in my case. But I just want to add that this is only valid if you are the owner of the repository -as the question point-. In my case I had the both case: I was the owner of the repo and can't push (question) but also no one else could push with the same error, but in case of the other users -no owners- you should just grant access to the repo (read and write or admin), AND here you have to pay to Atlassian if you have more than 5 users. Thanks for this answer. Nov 16, 2022 at 15:46
5

In the latest update you can set an app password from the bitbucket's settings page. Then when you will push or pull something type that password and it will workenter image description here

1
4

I had the same problem. It has something to do with a bug in Git for Windows. For me it was enough to change Git used in SourceTree to the embedded one:

Tools -> Options -> Git and click button 'Use Embedded Git'

0
3

I had the same problem. You need to go and add an app password for sourcetree in your bitbucket settings. Click "Bitbucket settings" in menu, App passwords, create app password. Then go to SourceTree and edit your saved password

3

For Mac Users. There was a default account set on the Source tree which does not allow me to clone the URL because my current URL was of different bitbucket account. So, It shows the invalid source path and I then click on Advance Options and found Authentication failed to your_clone_url. So, follow these steps

  1. Select Source Tree. Go to SourceTree menu -> Select Preferences.
  2. It will show Accounts window. Then Choose Accounts enter image description here

Here it will show list of your added accounts. Just click on Add button from the bottom and add your new bitbucket account details. It will list you account under Accounts tab. You can also set default account by clicking on Set Default .. button from bottom. Now all is done.

3

Inside company though it should work anywhere.

  • Logout from Bitbucket ( in case you are using)
  • Login with your credential
  • Go back to console
  • Fire the same command
  • It will ask for password - Provide it.
  • You are good to go.
2

If you made an account using google/ other oauth, then you need to set a bitbucket password for your account first. The URL for that is : https://bitbucket.org/account/user// or look for Bitbucket settings under the menu.

Then can login from git (I tried via command line). I use the built in manager for credentials :

credential.helper=manager

Now, after I set the password on the bitbucket site (email verified too), and tried to push again, it prompted me for the password, then pushed the code.

Menu location image on bitbucket web page -> http://ctrlv.in/747291 as of May 2016.

2

I got the same issue when password reset has happend for the domain. I tried almost all the steps in
(Tools > Options > Authentication). But nothing worked. At last i got below answer from atlassian community page and it worked.

The only thing that worked for me was navigating to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree and removing the passwd file

Once that file was deleted, I just did a "Push" and it finally asked for my password

https://community.atlassian.com/t5/SourceTree-questions/How-to-update-HTTP-S-credentials-in-sourcetree/qaq-p/297564

https://community.atlassian.com/t5/Sourcetree-questions/Getting-quot-fatal-Authentication-failed-for-quot-error/qaq-p/624663

1
  • I would just flag it is possible to delete an entry (userId and base64 string) from the passwd file, rather than delete the file.
    – Dazed
    Mar 25, 2022 at 9:29
2

I got this error using Azure DevOps even though I had added a Personal Access Tokens as the example shown.

enter image description here

Solved it by running git pull -v from Sourcetree terminal and adding the Personal Access Tokens again through there.

enter image description here

1
2

1.update git if necessary
2. add app password in bitbucket
https://bitbucket.org/account/settings/app-passwords/new
3. use this app password instead your account password to login

1
  • I was struggling with this then I created an account password MYACCOUNTPASSWORD and used it like this git push https://myusername:MYACCOUNTPASSWORD@bitbucket.org/myusername/myrepo.git
    – Omkar T
    Dec 12, 2022 at 6:24
2

For this issue you can use bitbucket's app password feature. This also works for github client/desktop authentication or any other app that requires you to connect bitbucket account. On bitbucket click on your avatar on top right then go to : personal settings -> app password and select 'create password'. Then a dialog box will appear asking you access permission you want to give to the app. mark the boxes and click on create, a password will appear in the box, copy that password and use it to authenticate your app. enter image description here

1

I Reverted to sourcetree 2.0

This solved the bug for me.

https://www.sourcetreeapp.com/download-archives

0
1

The issue for me was that I did not have an account added to Sourcetree.

Adding an account allowed me to push to my repo:

Tools > Options > Authentication > Add > Refresh OAuth Token

enter image description here

1

This problem occurs because the password of your git account and your PC might be different. So include your user name as shown in the below example:

https://myusername@bitbucket.org/...

https: //devi@bitbucket.org/...

1

OBSOLETE ANSWER - VERIFIED NOVEMBER 17, 2020


On Mac, I needed to go to Preferences > Accounts, then add a new account as Bitbucket Server and enter my company's bitbucket server URL. Then I had to choose HTTPS as the protocol and enter my username (without @email) and password.

Also I set this new account as the default account by clicking the Set Default... button in the bottom of the Preferences > Account page.

0
1

I was trying the git push --all bitbucket call and it was throwing back the "fatal: Authentication failed for 'https://..." response. The solution that worked for me was to change the command to:

git push --all https://{username}@{url}

On Windows, this popped up a dialog that allowed me to enter my password and the push worked.

0

None of the above worked for me - the problem lay in my Sourcetree Preferences. In the Network tab, I had a setting there for 'Default usernames for URLs which do not include one:'. The username was incorrect where I had entered it incorrectly previously - I had set it to my email rather than username. I highlighted the entries and clicked Remove for both. Then I returned to my repository page and clicked Push again. On pushing, it asked me for full username and password, which I was able to enter correctly - the push then finally worked.

0

I tried almost all the solution given here.

Which worked for me is I opened the GIT GUI and in that tried to Push. Which ask for the credentials, enter correct userid and password it will start working again.

0

I was using below command

git clone -b branch-name https://<username>@bitbucket.org/<repository>.git

Issue got resolved after adding password with username (see below command):

git clone -b branch-name https://<username>:<password>@bitbucket.org/<repository>.git
0

In windows this worked for me

git config --global http.sslVerify false

0

In IntelliJ IDEA, click Git menu at the top & click on Fetch option which should prompt for the Git credentials dialog box where we can enter our username & the new password to resolve this issue. Easy!

Not the answer you're looking for? Browse other questions tagged or ask your own question.