Skip to content

How to Fix Git Authentication Failed Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Git Authentication Failed Error. We cover key concepts, practical examples, and best practices.

You run git push or git pull and get Authentication failed — your credentials are expired, incorrect, or the remote requires a different authentication method.

The Problem

remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/user/repo.git'

Or:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please use a personal access token instead.

Step-by-Step Fix

Step 1: Update your credentials

git credential reject

Then:

git push

You will be prompted for new credentials.

Step 2: Use a personal access token (GitHub/GitLab)

# Use token as password when prompted
git push
Username: your-username
Password: your-personal-access-token

Step 3: Configure credential helper to cache credentials

git config --global credential.helper cache

Or store permanently (less secure):

git config --global credential.helper store

Step 4: Switch to SSH authentication

git remote set-url origin git@github.com:user/repo.git

Ensure SSH key is added:

ssh -T git@github.com

Expected:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Step 5: Check for expired tokens

# If using GitHub CLI
gh auth status
gh auth refresh

Step 6: Check remote URL format

# WRONG — includes username in URL
git remote set-url origin https://username@github.com/user/repo.git

# RIGHT — standard HTTPS URL
git remote set-url origin https://github.com/user/repo.git

Prevention Tips

  • Use SSH keys instead of passwords
  • Generate personal access tokens with appropriate scopes
  • Use a credential manager (Git Credential Manager Core)
  • Rotate tokens regularly and keep them in a password manager
  • Use gh auth login for GitHub CLI-based authentication

Common Mistakes with authentication failed

  1. Using return to exit a function early instead of wrapping a pure value in the monad
  2. Mixing let bindings with <- bindings in do notation, producing type errors
  3. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors

These mistakes appear frequently in real-world GIT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why did Git authentication stop working suddenly?

The most common reason is that GitHub and GitLab removed password authentication for HTTPS. Generate a personal access token and use it as the password. Other reasons: expired token, changed password, or 2FA enabled.

How do I generate a personal access token on GitHub?

Go to GitHub.com → Settings → Developer settings → Personal access tokens → Tokens (classic). Generate a new token with repo scope. Copy the token immediately — you will not see it again.

How do I switch a repository from HTTPS to SSH?

Update the remote URL: git remote set-url origin git@github.com:user/repo.git. Verify with git remote -v. Ensure your SSH key is added to your GitHub/GitLab account.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro