Git commands failing with URL rejected when using HTTP access tokens as Basic Auth

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

Performing git clone with access token as Basic Auth returns the following error:

1 2 3 λ: git clone http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git Cloning into 'repo'... fatal: unable to access 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git/': URL rejected: Port number was not a decimal number between 0 and 65535

OR

1 2 3 λ: git clone 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git' Cloning into 'repo'... fatal: unable to access 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git/': URL rejected: Port number was not a decimal number between 0 and 65535

Environment

  • Any version of Bitbucket Data Center that supports access tokens as Basic Auth.

Diagnosis

The same access token works fine when used as a Bearer token:

1 2 3 λ: git clone -c http.extraHeader='Authorization: Bearer BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia' http://localhost:7990/scm/project/repo.git Cloning into 'repo'... warning: You appear to have cloned an empty repository.

Cause

This is because the access token contains characters that breaks the URL syntax. The token will need to be URL encoded.

Solution

URL encode the token using the following command:

1 2 λ: echo -n "BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia" | jq -sRr @uri BBDC-MjAzMjgzMTU0NzU1Oix%2FXD3JWM30a7uPcI4xZ2nLnIia

And then use the encoded token within the git clone command:

1 2 3 λ: git clone http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix%2FXD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git Cloning into 'repo'... warning: You appear to have cloned an empty repository.

For a oneliner:

1 2 3 λ: git clone http://x-token-auth:$(echo -n "BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia" | jq -sRr @uri)@localhost:7990/scm/project/repo.git Cloning into 'repo'... warning: You appear to have cloned an empty repository.

Updated on March 14, 2025

Still need help?

The Atlassian Community is here for you.