Git for Windows with GCM Core not saving Bitbucket app password
Asked Answered
M

3

6

On a new machine I installed Git for Windows 2.37.1.windows.1, which also installed Git Credential Manager Core 2.0.785+6074e4e3d3. I created a Bitbucket app password. Then I tried to access a private repository on my Bitbucket account using e.g. git pull.

Git popped up an authentication dialog for Bitbucket. It had two options: authenticate with the browser, or authenticate with a password. I tried the password option first. I used my Bitbucket username and my newly created app password. I was able to access the repository.

But when I tried the exact same command, it popped up the authentication dialog again. I did the steps over and over. Each time it allowed me to access the repository, but it appeared the credentials were not being saved.

I opened Credential Manager in Windows and saw credentials for git:https://bitbucket.org.

I tried to access the repository again, but this time I selected the option to authenticate with the browser. It sent me to some web page, and since I was already logged on at the Bitbucket site, it said I was authenticated. I was able to access the repository. And now I am able to access the repository without an authentication dialog each time.

Note that if I create a GitHub personal access token and enter it in the authentication dialog, Git seems to save it so I'm not required to enter it each time.

Why didn't Bitbucket store my credentials? Why did it require me to authenticate through the browser? If I'm forced to authenticate through the browser, what's the point of having an app password? And where is this specific scenario documented?

Update After authenticating with the browser (one of the two options in the "Connect to Bitbucket" authentication dialog in Git for Windows), I was able to continue using Git without further authentication on the Windows 10 Command Prompt. Ah, but then I switched to PowerShell and the whole thing happened all over again: I got the authentication dialog every time I tried to e.g. git push. Each time I was successful with the "Password" option, using my app password, but it never saved the password, requiring me to reenter the password each time.

So once again I chose the "Browser" option in the dialog; it took me to a Bitbucket web page, which said (as I was already logged in):

Authentication Successful Git Credential Manager has been successfully authenticated. You may now close this page.

Now I can git push as much as I like from PowerShell, now that I authenticated using "Browser".

So the question remains: why does Bitbucket's authentication dialog for Git for Windows use the saved app password and instead require that I reenter it each time? (Note that I have since updated to Git for Windows 2.37.2.windows.2.)

Massotherapy answered 10/8, 2022 at 23:12 Comment(1)
You're probably aware but just for future reference: You can always consider using SSH instead of HTTPS.Vierno
Z
1

using an account password git over https and account password is stored keychain access and use instead of the app

first run the following command :

git config --system credential.helper

git config --global credential.helper

then make a push from the terminal. you should get asked for a password if none is stord keychain access, please provide the app password

this answer has been tried by several people, see this link: https://community.atlassian.com/t5/Bitbucket-questions/Always-seenig-a-mesage-Using-an-account-password-for-Git-over/qaq-p/1919111

Zollie answered 13/9, 2022 at 0:31 Comment(0)
N
0

Being in exact same situation on two servers I resolved it using the command

git config --global credential.bitbucketAuthModes "basic"

from this link

I didn't had to reenter the password anymore and the one from the windows credential manager is now used.

However, This resolved the behaviour on one server only. So certainly not the correct solution yet but only partial solution.

I can't reproduce it on the second server.

EDIT: I was assuming that both servers where using same configurations but the git version differs :

  • Working server: Git version 2.35.1.windows.2
  • Not working server: Get version 2.38.1.windows.1

Note: I'm using a proxy on both server, I wonder if it is not the source of the issue.

Notable answered 7/11, 2022 at 10:37 Comment(0)
M
-1

First, make sure the issue persists with Git for Windows 2.37.2(2) released 6 days ago (Aug. 12th, 2022)

Second, make sure to register an App password as your password.
(An app password is a user-based access tokens for scripting tasks and integrating tools (such as CI/CD tools) with Bitbucket Cloud).
As explained by "Announcement: Bitbucket Cloud account password usage for Git over HTTPS and API ending March 1, 2022":

If you have saved your credentials (i.e., username and account password) in a credential manager such as Git Credential Manager (GCM), Windows Credential Manager, OS X Keychain, or some other third-party application, then you will need to update them with an app password before March 1, 2022, in order to continue using Basic authentication with the Bitbucket API and/or Git over HTTPS without disruption


Here is how to update GCM with an app password on Windows:

In a CMD, set a simplified PATH like:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set "GH=%LOCALAPPDATA%\Programs\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Then type in the same CMD:

printf "Host=bitbucket.org\nprotocol=https" | git credential-manager-core get
# or 
printf "Host=bitbucket.org\nprotocol=https\nusername=YourBitBucketAccount" | git credential-manager-core get

If you do not see your token (app password for BitBucket Cloud), register it manually:

printf "Host=bitbucket.org\nprotocol=https\nusername=YourBitBucketAccount\npassword=YourAppPassword" | git credential-manager-core store

Then try again, even without cloning, with a git ls-remote https://bitbucket.org/you/YourPrivateRepo.
If it lists branches, the authentication worked.

Manama answered 17/8, 2022 at 16:6 Comment(4)
The answer you gave is for HTTP access tokens, for Bitbucket Server. This question is about app passwords for Bitbucket cloud, which are completely separate things. This answer is not helpful to my situation.Massotherapy
@GarretWilson I have updated the answer for BitBucket Cloud.Manama
Your updated answer seems out of date. It mentions to use git credential-manager get, but Git has switched from credential-manager to credential-manager-core. See github.blog/… and github.com/GitCredentialManager/git-credential-manager .Massotherapy
You may be using a legacy installation. Remove your credential.helper value and reinstall Git. See https://mcmap.net/q/1918704/-why-does-git-for-windows-helper-manager-not-work-on-new-machine .Massotherapy

© 2022 - 2024 — McMap. All rights reserved.