How to fix “git authentication failed” error

Greg Foster
Greg Foster
Graphite software engineer

The "git authentication failed" error typically occurs when Git operations requiring network access (like clone, fetch, push) are blocked due to incorrect or missing authentication credentials. This might happen for several reasons:

  • Incorrect username or password

  • Expired or revoked access tokens

  • Incorrectly configured SSH keys

  • Changes in repository permissions

This guide aims to provide solutions to common scenarios where authentication issues arise in Git, covering a variety of environments including Windows, macOS, and using Git GUI tools.

  • Scenario: Error appears when cloning a repository, typically if it's private or requires specific permissions.

  • Solution: First, ensure you're using the correct URL for cloning. If cloning through HTTPS, you might need to enter your username and password (or personal access token for services like GitHub). If cloning through SSH, make sure your SSH key is added to your account and your SSH agent is running.

  • Scenario: Attempting to fetch updates from or pull changes to a remote repository.

  • Solution: Similar to cloning, verify that your credentials are correct. For HTTPS, consider using a personal access token instead of a password, especially on platforms like GitHub that have deprecated password authentication for Git operations.

  • Windows Credential Manager: Git for Windows users might face authentication issues if their stored credentials are outdated or incorrect. Open Windows Credential Manager and update or remove the credentials related to Git or your repository host.
  • Scenario: Using a graphical interface for Git operations, such as Git GUI or third-party tools.

  • Solution: Ensure the GUI tool is configured to use the correct authentication method (SSH/HTTPS). Check the tool's settings for managing credentials or tokens, and update them if necessary.

  • Keychain Access: On macOS, Git credentials can be stored in the Keychain. If authentication fails, open Keychain Access and search for your Git host (e.g., "github.com"). Update the stored password with your PAT or delete the entry to prompt for fresh credentials on the next Git operation.
  • Update remote URL: If you're still using a password for HTTPS operations, switch to a personal access token. You can also change the repository's remote URL to use SSH if you prefer key-based authentication:

    git remote set-url origin git@github.com:username/repository.git

  • Use SSH when possible: SSH keys provide a secure and convenient way to authenticate without entering credentials repeatedly. Ensure your public key is added to your Git hosting service and your private key is loaded in your SSH agent.

  • Update Git: Ensure you're using the latest version of Git, as updates often include improvements and fixes for authentication mechanisms.

  • Check for 2FA: If you have two-factor authentication enabled on your Git hosting service, password authentication might not work, necessitating the use of a personal access token or SSH key, in addition to a second method of authentication such as a yubikey.

  • Verify permissions: Make sure your user account has the necessary permissions for the repository you're trying to access. If all else fails, contact one of the administrators of your repository.

For further information on authentication errors, see the official git documentation.

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2