GitLab
HTTP Basic Authentication
Access Denied
Git Errors
Remote Repository Issues

GitLab "remote: HTTP Basic: Access denied" and fatal authentication failed

Codemia Knowledge Hub ·

The GitLab error remote: HTTP Basic: Access denied usually means Git tried to authenticate over HTTPS with credentials GitLab no longer accepts, or with a token that lacks the needed scope. The fix is almost always to stop using your account password and switch to a valid personal access token or to SSH.

Why GitLab rejects the password

When a remote uses an HTTPS URL like:

text
https://gitlab.example.com/group/project.git

Git needs credentials for push, fetch, or clone. Modern GitLab setups commonly reject plain account passwords for Git over HTTPS. GitLab expects one of these instead:

  • a personal access token
  • another supported token type for the instance
  • SSH key authentication, if you switch the remote to SSH

So although the error mentions HTTP Basic, the real problem is usually the wrong credential type, not GitLab being down.

Fix it with a personal access token

To stay on HTTPS, create a GitLab personal access token with the scopes your operation needs, then enter that token where Git asks for a password.

Check the remote first:

bash
git remote -v

If it shows an HTTPS URL, the next push or fetch will use HTTP authentication. Clear the saved credential and fetch again:

bash
1git credential reject <<EOF
2url=https://gitlab.example.com
3EOF
4git fetch

When Git prompts, enter:

  • your GitLab username
  • the personal access token as the password

If your operating system has a credential manager, you may need to clear the old saved password there too.

Switch the remote to SSH

Many developers avoid HTTPS token prompts entirely by using SSH:

bash
git remote set-url origin [email protected]:group/project.git
ssh -T [email protected]
git fetch origin

If the SSH key is correctly added to GitLab, this usually avoids the HTTP Basic error completely. SSH is often the smoother long-term option, especially on machines where you already manage keys for several repositories.

A token that used to work can still fail

A token can exist and still be rejected because:

  • it expired
  • it was revoked
  • it lacks write access for pushes
  • it lacks read access for clones or fetches

If the error appeared suddenly on a setup that used to work, check the token's status before changing anything else. This is also why embedding a token in the remote URL is a poor habit: it solves one prompt but makes token rotation and auditing harder.

Stale credentials in the credential helper

Git clients often cache old credentials aggressively, so you can create a correct token and still keep sending the old password. Check which helper is configured:

bash
git config --get credential.helper
git config --show-origin --get-all credential.helper

If a helper is set, remove or refresh the stale entry in that credential store. Otherwise Git may never ask for the new token.

A wrong remote URL can look like an auth error

Check for:

  • wrong hostname
  • wrong group or project path
  • unexpected redirect from HTTP to HTTPS
  • a username embedded in the URL from an old setup

Confirm the URL directly:

bash
git remote get-url origin

A correct token will not help if the remote path is wrong.

Accounts with two-factor authentication

With two-factor authentication enabled, a normal password is even less likely to work for Git over HTTPS. Token or SSH authentication is the intended path, so on such an account read "HTTP Basic: Access denied" as "use a token or SSH," not "retype the password more carefully."

Mistakes that keep the error coming back

  • Using your normal GitLab password for an HTTPS remote.
  • Creating a token without the scopes the operation needs.
  • Leaving stale credentials in the OS credential manager or Git credential helper.
  • Embedding tokens in remote URLs and forgetting they expired.
  • Debugging GitLab server health before confirming the local client sends the right kind of credential.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design