Getting intermittent authentication problem with BitBucket Server while doing git clone or git pull.

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

While trying to clone a repository, there is an authentication failed response 2-3 times without getting prompted for the credentials.

git clone https://bitbucket.testing.com/scm/~test/test-demo.git
Cloning into 'test-demo'
fatal: Authentication failed for 'https://bitbucket.testing.com/scm/~test/test-demo.git/'

After that, it is prompted to enter the credentials and the clone works fine.

Environment

Bitbucket Server/ Data Center version 7.6 + and above

Diagnosis

The atlassian-bitbucket.log, shows similar log entries for the authorization failure.

2022-06-10 11:25:18,498 INFO  [http-nio-7990-exec-925] @KXZGRTx685x337794699x2 54.93.107.158,127.0.0.1 "GET /scm/~test/test-demo.git/info/refs HTTP/1.1" c.a.c.m.a.ApplicationServiceGeneric Invalid credentials for user TestUser in directory mydirectory (262145), aborting

Once the git debug logging is enabled, we can see similar lines for the event of the failure.

15:15:07.021513 run-command.c:666       trace: run_command: 'git credential-store get'
15:15:07.024304 git.c:455               trace: built-in: git credential-store get
15:15:07.024664 http.c:756              == Info: Couldn't find host bitbucket.testing.com in the .netrc file; using defaults

If you want to compare, you can see the below entries when the try is successful. 

15:18:27.440380 run-command.c:666       trace: run_command: 'git credential-store get'
15:18:27.442953 git.c:455               trace: built-in: git credential-store get
Username for 'https://bitbucket.testing.com': TestUser
Password for 'https://TestUser@bitbucket.testing.com': 
15:18:34.966706 http.c:756              == Info: Couldn't find host bitbucket.testing.com in the .netrc file; using defaults

Cause

Here the git-credential store is the reason for the failure. Once a password gets stored in it, it remains there and those credentials are used for the user authentication for git operations. There could be password policies set in the organization that will force you to change your passwords in a couple of months. But since the wrong password is already stored in the git-credential store, you will be getting the authentication error.

Solution

Unset the git the credential helper using the below command before running a git pull/clone. This should be a one time activity. 

git config --unset credential.helper

If this doesn't fix the issue, try unsetting it globally using the below command.

git config --global --unset credential.helper

The people who have used the credential.helper tend to miss the convenience of it and will need to enable it again with the correct password. (smile)  You can run the below command for that before you run any git command.

git config credential.helper store
Last modified on Sep 15, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.