How to Fix “Git Authentication Failed”

A Git authentication error means the hosting service could not verify your identity or authorize the requested operation. The fix depends on whether your remote uses HTTPS or SSH. Check the URL and your repository access first, then refresh only the credentials for the method you actually use.

Practice Git workflows →

1. Check the remote URL and repository permissions

First see which host and protocol the repository uses:

git remote -v

HTTPS URLs generally start with https://; SSH URLs commonly use a form such as git@github.com:OWNER/REPO.git. Check for spelling mistakes, confirm the repository exists, and verify that the signed-in account has access. For a push, you also need permission to write to the repository; being able to clone does not always grant push access.

Fix authentication for an HTTPS remote

Most Git hosts do not accept an account password for Git over HTTPS. Use the host’s supported browser sign-in, credential manager, or access token flow. When a token is required, create it through the provider and grant only the permissions needed for this repository. Do not put tokens directly in the remote URL, scripts, or commands that may be recorded in shell history.

Refresh a saved HTTPS credential

A credential manager may keep using an expired token or the wrong account. Sign out of the stored account or remove the saved credential using your operating system’s credential manager, then run the Git operation again and sign in with the correct account. The exact steps depend on the credential helper configured on your machine:

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

Avoid printing or sharing stored credentials. If an access token was exposed, revoke it at the provider and create a replacement.

Fix “Permission denied (publickey)” for SSH

This message usually means the SSH host did not accept a key offered by your computer. Confirm that the remote URL is the SSH URL, then check that the public key for your account matches a key available locally.

  1. Check whether you already have a public key, such as ~/.ssh/id_ed25519.pub.
  2. Add the public key to the correct account on your Git host. Never upload or share the private key file, which does not end in .pub.
  3. Make sure the SSH agent is running and has the matching private key loaded, or configure your SSH client to use that key.
  4. Test the connection using the host’s documented SSH test command. A successful identity check confirms authentication, but repository permissions are still checked separately.

If you do not need SSH, switching the remote to its HTTPS URL is a valid alternative. Use the URL copied from the repository’s hosting page rather than guessing its format.

Common authentication messages

“Authentication failed” or “Invalid username or token”

For HTTPS, the saved username or credential may be wrong, expired, or missing required permissions. Remove the stale entry from the configured credential manager and authenticate again. Confirm the account is authorized for the repository.

“Repository not found”

This can mean the URL is incorrect, the repository was moved, or your account cannot see a private repository. Check the URL and access with the repository owner.

Authentication works, but git push is rejected

Authentication identifies you; it does not guarantee write access or that your local branch is up to date. Check your role and branch protection rules. If the error says the remote contains work you do not have, follow the guide to fixing a non-fast-forward push rejection.

Why you should not disable SSL verification

Do not use git config http.sslVerify false as an authentication fix. It disables certificate verification and can expose your connection to interception; it also does not correct a bad password, missing permission, or SSH key. If Git reports a certificate error, diagnose the certificate or network configuration separately instead of turning verification off.

Frequently asked questions

Why does Git ask for my password when I push?

Your HTTPS remote may be using a credential prompt or helper. Most hosting services require a supported browser flow, credential manager, or token instead of your account password.

Can I use HTTPS and SSH in the same repository?

Yes. A repository has a remote URL for each remote, and you can change one with git remote set-url. Choose a protocol you have set up and keep the remote URL free of credentials.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →