How to fix “git authentication failed” error

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


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.

Join 20,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2
  • 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.

While Git is an incredibly useful tool, it has many shortcomings, particularly with rebasing, and managing stacked pull requests.

The Graphite CLI simplifies git, handles rebasing automatically, and allows you to create, submit, and stack pull requests right from the command line.

Under the hood, the CLI runs Git to create branches, commits, and metadata, which means you can still use Git in your scripts, tooling, or whenever you feel like it. Read more about authenticating and installing the Graphite CLI in our docs.

screenshot of the Graphite CLI

  • 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.
Join 20,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2
  • 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.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2