Cannot use access token with git commands over https

Summary

We cannot use access tokens with git commands in the URL over https

Steps to reproduce

Setup repo and personal access token with api,read-repository,read-user, and sudo scope. From command line, execute a command like: git ls-remote https://oauth2:ACCESS_TOKEN@gitlab.host.com:443/support/monitoring.git Receive error: fatal: Authentication failed for 'https://oauth2:ACCESS_TOKEN@gitlab.host.com:443/support/monitoring.git/'

If however, we don't include oauth2:access_token in the URL and just do: git ls-remote https://gitlab.host.com:443/support/monitoring.git

Username for 'https://gitlab.host.com:443': oauth2 Password for 'https://oauth2@gitlab.host.com:443': [ACCESS_TOKEN]

We get as expected: 7de8a4e452fcaf4228afd9d87b06340d423e0605 HEAD 7de8a4e452fcaf4228afd9d87b06340d423e0605 refs/heads/master

So the access token works when we are prompted for a username/password but NOT when it's included in the URL.

What is the current bug behavior?

Currently we cannot pass a username and token in the URL when running git commands over https.

What is the expected correct behavior?

Run git commands with a username and token in the URL and not get authentication failures.

Edited Sep 10, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading