GitLab: "remote: HTTP Basic: Access denied" on git clone, fetch or push
Git reached GitLab, sent a username and a password or token, and GitLab did not accept them. With two-factor authentication on, a password does not work for Git at all; a token must be correct, unexpired and have the right scope. The usual fix is a personal access token with read_repository (or write_repository to push), used as the password together with your GitLab username, after removing any older token that Git stored. The same expired token gets a different answer from GitLab's API (401 invalid_token); Git over HTTPS gets the Basic authentication text below.
The whole message
GitLab.com's answer, as Git prints it (checked November 22, 2026; GitLab's text is the same on the web page it links to, Troubleshooting Git):
remote: HTTP Basic: Access denied. If a password was provided for Git authentication, the password was incorrect or you're required to use a token instead of a password. If a token was provided, it was either incorrect, expired, or improperly scoped. See https://gitlab.com/help/topics/git/troubleshooting_git.md#error-on-git-fetch-http-basic-access-denied fatal: Authentication failed for 'https://gitlab.com/GROUP/PROJECT.git/'
The text covers two cases, a password and a token, and does not say which one GitLab saw. The sections below separate them.
To replace an expired token in one place: Merge Request (MR) Review Inbox for GitLab, a plugin for JetBrains IDEs, says on a 401 that the token expired, was revoked or is from another GitLab instance, and keeps the token in the IDE's password safe, so replacing it there is the only change.
Why GitLab refuses (GitLab's list)
From GitLab's troubleshooting two-factor authentication page:
- You have enabled 2FA and attempted to authenticate with a username and password.
- You have not enabled 2FA, but it is mandatory for the GitLab instance. This applies to GitLab.com.
- You have not enabled 2FA and attempted to authenticate with an incorrect username or password.
- You have not enabled 2FA and the enforce 2FA for all users setting is active.
- You have not enabled 2FA and the Allow password authentication for Git over HTTP(S) checkbox is not selected (a setting of a Self-Managed instance).
The same page names the fixes: a personal access token with the right scope (read_repository or write_repository for Git over HTTP(S); the registry scopes read_registry and write_registry for container images), an LDAP password if you configured LDAP, or an OAuth credential helper. A token without one of the scopes your Git action needs is the "improperly scoped" of the message; insufficient_scope is the API's answer to a missing scope.
Fix 1: a token as the password, with a username
Create a personal access token with read_repository (and write_repository to push), then give Git your GitLab username and the token as the password. Git for Windows 2.46.0 and later can fail with this very error when the username is empty, so GitLab's docs give the username in the URL, using one of these:
git clone https://USERNAME@gitlab.com/path/to/a/project.git git remote set-url origin https://USERNAME@gitlab.com/path/to/a/project.git git config --global url."https://USERNAME@gitlab.com/".insteadOf "https://gitlab.com/"
On a Self-Managed server, use its host name in place of gitlab.com.
Fix 2: remove the old token Git stored
A credential helper keeps the first token you gave it and sends it again every time, so an expired, revoked or rotated token keeps producing this error even after you made a new one. GitLab's docs remove the stored credential like this, and Git asks again at the next HTTPS command:
printf "protocol=https\nhost=gitlab.com\n" | git credential reject
For a Self-Managed server, put its host name after host=. When Git asks, enter your GitLab username and the new token as the password. Tokens expire at midnight UTC on their expiry date and cannot be reactivated; the token page has how to create the new one.
Check the token without Git
To see GitLab's own answer for a username and token, ask for the first page Git asks for, with curl:
curl -i --user USERNAME:TOKEN "https://gitlab.com/GROUP/PROJECT.git/info/refs?service=git-upload-pack"
(info/refs is the first path of a Git request over HTTP, Git's HTTP protocol; GitLab's docs show it in its logs.) HTTP 200 and a Content-Type of application/x-git-upload-pack-advertisement mean the username and token work for reading, so the fault is in what Git stored. HTTP 401 with the text above means GitLab refuses them. Two things seen on November 22, 2026 on GitLab.com, with a made-up token:
- A public project answered 200 with no credentials and 401 with the made-up token. So with
curl --usera wrong token fails even on a project anyone may read. - Git itself, given the same made-up token in the URL (
git ls-remote), read that public project without error: Git sends credentials only after a 401, and a public project gives none. The error then shows up on a private project or at the first push, which is why the same token seems to work in one place and fail in another.
When it turns into 403
GitLab's docs list a second message, fatal: unable to access 'https://gitlab.com/group/project.git/': The requested URL returned error: 403, for a client IP address that was blocked by the failed-authentication ban, and say that the limits differ between Self-Managed and GitLab.com. On Self-Managed, a 401 for GET /group/project.git/info/refs followed by a 200 a few milliseconds later in production_json.log is normal: Git's first request carries no credentials. A 401 with no 200 after it points to a wrong password or an expired or revoked token (Troubleshooting Git).
GitLab merge requests and pipelines in IntelliJ IDEA
Lesstep makes two plugins for JetBrains IDEs 2024.1 or later that read GitLab with read_api and change things with api: Merge Request (MR) Review Inbox for GitLab and Pipelines and Jobs Inbox for GitLab CI. When GitLab refuses the token with 401 while they read, they say that the token expired, was revoked or is from another GitLab instance, show GitLab's own description, and offer to open their settings, which have a link to GitLab's form with the name and scope filled in (GitLab 16.7 or later). The token is kept in the IDE's password safe, so replacing it there is the only change. Reading is free; approving, commenting and merging, or retrying, cancelling and running pipelines, are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
GITLAB is a trademark of GitLab Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitLab Inc. or JetBrains.
More: GitLab 401 "invalid_token" · GitLab "insufficient_scope" · GitLab 404 "Project Not Found" · GitLab 429 "Retry later" (rate limits) · GitLab approval refused (401, 409) · git clone "SSL certificate problem" with GitLab · GitLab SSH "Permission denied (publickey)" · GitLab merge request plugins for IntelliJ IDEA, compared · 日本語