165

My Bitbucket password is correct because I can easily log in with this password. When I try to push a project or file to Bitbucket it shows "Invalid credentials error".

git push -u origin master

fatal: Invalid credentials
Password for 'https://username@bitbucket.org':
remote: Bitbucket Cloud recently stopped supporting account passwords for Git authentication.
remote: See our community post for more details: https://atlassian.community/t5/x/x/ba-p/1948231
remote: App passwords are recommended for most use cases and can be created in your Personal settings:
remote: https://bitbucket.org/account/settings/app-passwords/
fatal: Authentication failed for 'https://bitbucket.org/username/demo.git/'

How can I solve this issue?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Zahidul Islam
  • 1,896
  • 2
  • 8
  • 13

16 Answers16

242

When prompted to log in, use your username, but instead of your usual account password, use the app password:

To get the app password

  1. Go to the bitbucket.org website and log in
  2. From your gear in the upper right, and click Personal Bitbucket settings
  3. Click App passwords under Access management
  4. Click Create app password
  5. Give the app password sufficient rights (probably write on the repo at a minimum), and a label related to the application that will use the password
  6. Don't forget to save that password
Marc
  • 3,259
  • 4
  • 30
  • 41
Asyraf Arifin
  • 2,445
  • 2
  • 7
  • 11
  • 4
    [MacOS] If you still facing issue after above steps, try cloning project again. – Faisal Hassan Mar 10 '22 at 07:43
  • 1
    [Windows] you can remove previous bitbucket token credentials stored in your machine using CREDENTIAL MANAGER in windows – Supun Sandaruwan Mar 15 '22 at 06:22
  • [MasOS] [Sourcetree] 7. Sourcetree -> Preferences -> Accounts 8. Create Account with new passowrd 9. Now you can clone via HTTPS – Marc Mar 16 '22 at 11:44
  • 4
    Do not forget to set needed permissions - at least Account Read and Repositories Read and Write! – David Najman Mar 18 '22 at 11:11
  • 1
    Also, the username value is at general/account-settings/bitbucket-profile-settings@username – Daniel Cassiano Chaves Nov 22 '22 at 23:51
  • many thanks this is really work and helped me – Mosa Mar 30 '23 at 10:10
  • WTF, I've setup an ssh key and everything and THIS was it? Man, that's carzy, thanks a lot! – cV2 Mar 30 '23 at 14:35
  • @Marc please update this answer with permission settings, as 'just creating an app password' does not work without guessing the right permissions – Alex V Apr 29 '23 at 13:35
  • @AlexV - I've added some comment on permissions, but if someone can't recognize what permission is necessary for pushing to a repo, I'm pretty sure they not should be doing so. – Marc May 01 '23 at 14:07
61

After 2022-03-01:

Beginning March 1, 2022, you will no longer be able to use your Atlassian account password when using Basic authentication with the Bitbucket Cloud REST API or Git over HTTPS.

  1. Go to: Personal settings, App passwords
  2. Create app password
  3. Tick the necessary permissions for your needs. Account Read and Repositories Read and Write are needed for basic Git actions.
  4. Save the password. You can not view it again!
  5. Use the generated password to log in. You might need to use your Bitbucket username that you can find on Personal settings, Account settings under "Bitbucket profile settings" (saw a post that told specifically to use the username don't know if it is true).

More information about app passwords is on App passwords.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mikk Raudsepp
  • 707
  • 4
  • 6
  • Now, which are the "necessary permissions for [my] needs"? Using command-line git and have no idea which permissions are necessary beyond 'repositories' read and write??? – leanne Mar 10 '22 at 21:51
  • 1
    Added that part to point nr 3. – Mikk Raudsepp Mar 11 '22 at 12:18
  • Can you add that as an answer, Mikk, to [my SO question here](https://stackoverflow.com/q/71431354/1107226)? (Just the permissions part) – leanne Mar 11 '22 at 14:53
  • This one explained it best. The page i came across in the bitbucket page only explained why it is not supported anymore but does not provide instructions on what to do next. – chitgoks Mar 12 '22 at 06:17
  • 1
    Isn't this backwards? They used to support OAuth, which was both user-friendly and secure. Are you sure you are not misunderstanding something, or the problem is really something else? – Florian Winter Mar 14 '22 at 11:25
  • What specifically is the "Account Read" permission for? Doesn't the Git CLI just need to access the repository? – Garret Wilson Aug 10 '22 at 20:18
  • should be the best answer instead of the above upvoted, because of the permission settings tip: creating app password is obvious, but setting the right permissions not - only point No 3 helped me to push code to bitbucket – Alex V Apr 29 '23 at 13:32
36

After successfully creating the app password as mentioned by Asyraf Arifin:

To use Bitbucket "App Password" over HTTPS, you can then navigate to particular repository's path in Terminal then set the remote origin (for an already-cloned repository):

git remote set-url origin https://<Bitbucket_Username>:<App_Password>@bitbucket.org/<Bitbucket_Username>/<Repo_Name>.git

For a new clone:

git clone https://<Bitbucket_Username>:<App_Password>@bitbucket.org/<Bitbucket_Username>/<Repo_Name>.git

enter image description here

Anish
  • 595
  • 1
  • 4
  • 16
34

I had the same problem with my JetBrains IDE. It was showing a password dialog when I tried updated project sources or push my commits.

enter image description here

I solved the problem by following the below steps

  • Open App Passwords page of personal settings on the Bitbucket enter image description here
  • Click on Create app password and tick at least the read and write permissions of the repositories for the basic pull and push actions. Then give some label and submit by Create. enter image description here
  • The generated app password should be passed in IDE enter image description here
Artyom Vancyan
  • 5,029
  • 3
  • 12
  • 34
  • For those looking for a solution using VS Code, the idea is pretty similar. When entering the push command a new prompt should appear at the top of the screen saying that you can press 'Enter' to push. This will fail because you are actually supposed to paste the password in the little text box that say 'Password' just above. So you just copy and paste like here and voilá. – Lucas S. G. Apr 16 '22 at 07:05
  • What JetBrains IDE? JetBrains is the name of the company. They have [many IDEs](https://en.wikipedia.org/wiki/JetBrains#IDEs), e.g. [IntelliJ IDEA](https://en.wikipedia.org/wiki/IntelliJ_IDEA), [PhpStorm](https://en.wikipedia.org/wiki/PhpStorm), and [PyCharm](https://en.wikipedia.org/wiki/PyCharm). – Peter Mortensen Apr 23 '22 at 14:59
  • @PeterMortensen It doesn't matter which one, as VCS works the same for all the IDEs listed above. – Artyom Vancyan Apr 24 '22 at 08:08
  • Working with VScode as well :) :) – Binary_Hits00 Sep 05 '22 at 14:25
25

My answer is just a compilation of Mikk Raudsepp's and Anish's answers.

  1. Go to: Personal settings, App passwords

  2. Create app password

  3. Tick the necessary permissions for your needs.

  4. Copy the generated password

  5. On Terminal

    On an already-cloned project:

     git remote set-url origin https://<Bitbucket_Username>:<App_Password>@bitbucket.org/<username/repoName>.git
    

    To clone a new project:

     git clone https://<Bitbucket_Username>:<App_Password>@bitbucket.org/<username/RepoName>.git
    

Why is it happening? -

Beginning March 1, 2022, you will no longer be able to use your Atlassian account password when using Basic authentication with the Bitbucket Cloud REST API or Git over HTTPS.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Fe3back
  • 924
  • 7
  • 15
17

Go to Personal settings from the menu at the top. Click on App passwords and set up the permissions as required as shown below.

Copy the generated password and use it on the authentication prompt. This will resolve the issue.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sudin
  • 314
  • 2
  • 11
5
  • Go to Credential ManagerWindows CredentialsAdd a generic credential

  • Fill up the fields:

    • Network address: git:https://bitbucket.org
    • Username:
    • App Password:

It was solved by this question.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zahidul Islam
  • 1,896
  • 2
  • 8
  • 13
4

If any Linux user is facing the same issue, please follow the steps given below.

  1. Go to bitbucket.org
  2. Click on the Login link
  3. At the bottom left, click on your avatar icon (your profile picture).
  4. Then click Personal settings or you can open Personal settings, Account settings directly
  5. In the Access Management section, click on the App password link or you can go directly to Personal settings, App passwords
  6. Click on the Create App password button.
  7. Give the access rights as per your requirement.
  8. Click on Create.
  9. You get the pop up with a password. Copy that password somewhere in your laptop or pc (the given password will be difficult to remember).
  10. Now whenever you’re are performing a Git operation, like pull or push and if they asked for password. Instead of using your login password, you need to use the above password (one which is generated by the app password).
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Atit More
  • 137
  • 7
2

In my case I had no option to create app passwords. Instead there was an option to create Personal access tokens. Now, once you create a token, you have to put the same token in place of the password. This works in Android Studio / IDEA as well as on the command prompt.

enter image description here

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
NeeK
  • 662
  • 1
  • 8
  • 21
2

[![enter image description here][1]][1]

enter image description here

Note in Repository Need Admin access and use updated password in terminal

Sourabh Gera
  • 862
  • 7
  • 7
1

I created an app password, made sure the user is username and not email, then updated the app password in Windows' Credential Manager. Adding the app password in the repository path finally resolved my issue:

From:

https://username@bitbucket.org/...

To:

https://username:app_password@bitbucket.org/...
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Livshin
  • 15
  • 5
0

Try setting-up passwordless login. With this method, you will never need to worry about remembering the password again on your machine (but don’t use this technique on public computers)

See Atlassian documentation: Set up an SSH key

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Sunil Garg
  • 484
  • 5
  • 9
0

If you already generated an app password, if you are using VSCode and you have installed the Atlassian extension, then click on the git pull/push button and this will open the login dialog. Click authorize and that's it. Now you are logged in.

enter image description here

Gabriel Arghire
  • 1,992
  • 1
  • 21
  • 34
0

I had some problems with this on my Mac using Android Studio. I fixed it by going into the Android Studio terminal tab and writing

git push 

Then it told me that fatal: The current branch blabla_branch_name has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin blabla_branch_name

So I copied and pasted that into the terminal and hit enter again. This time it asked me for a password. I went into my bitbucket account online and created a new app password. Then I copied that password that it created, and pasted it into the terminal and hit enter. This seems to have reconnected the device and bitbucket and things work again.

The Fluffy T Rex
  • 430
  • 7
  • 22
-1

For Mac users:

cd Library/Application\ Support/SourceTree

Delete your username here.

You can log in again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
-1

Try creating ssh key and add ssh key to the bitbucket and try

prachi
  • 113
  • 1
  • 8