How to fix fatal: Authentication failed for 'https://github.com/user/repo.git/' in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 649 views

The 'Authentication failed' error occurs when Git cannot verify your credentials with the remote repository. This typically happens because GitHub no longer accepts password authentication for HTTPS, requiring you to use a Personal Access Token or switch to SSH authentication.

Quick fix

Fixes fatal: Authentication failed for 'https://github.com/user/repo.git/'

git push origin main
# When prompted for password, paste your Personal Access Token
  1. Generate a Personal Access Token on GitHub
  2. Clear cached credentials from your system
  3. Configure Git to cache your new credentials
  4. Switch from HTTPS to SSH authentication
git — error
git push origin main
# When prompted for password, paste your Personal Access Token
fatal: Authentication failed for 'https://github.com/user/repo.git/'

What this error means

This error indicates that Git's attempt to authenticate with the remote repository (typically GitHub, GitLab, or Bitbucket) was rejected. The remote server could not verify your identity using the credentials provided. Since August 2021, GitHub no longer accepts password authentication for Git operations over HTTPS. This is the most common cause of this error for GitHub users. Instead of your password, you must use a Personal Access Token (PAT) or authenticate via SSH. The authentication process works as follows: when you push, pull, or clone over HTTPS, Git sends your credentials to the remote server. If the server cannot validate these credentials, it returns this "Authentication failed" error. This can happen for several reasons: 1. **Password authentication is disabled** - Most Git hosting services now require tokens or SSH keys 2. **Incorrect or expired credentials** - Your cached credentials may be outdated 3. **Two-factor authentication** - 2FA requires special tokens rather than passwords 4. **Credential manager issues** - Stored credentials in your OS credential manager may be corrupted or stale

Typical symptoms

  • Git push fails with 'fatal: Authentication failed for' message
  • Git pull or fetch returns authentication error
  • Git clone fails when accessing a private repository
  • Commands that previously worked suddenly fail after password change
  • Authentication fails despite entering correct password
  • Error appears after enabling two-factor authentication
  • CI/CD pipelines fail with authentication errors
  • Error occurs only on one machine but works on another

Common causes

  1. Using password instead of Personal Access Token (PAT) with GitHub
  2. Personal Access Token has expired or been revoked
  3. Two-factor authentication (2FA) enabled but using password
  4. Cached credentials in credential manager are outdated
  5. Incorrect username entered during authentication
  6. Repository permissions have been changed or revoked
  7. Git Credential Manager is corrupted or misconfigured
  8. Using wrong remote URL (HTTP vs HTTPS vs SSH)
  9. Corporate proxy or firewall interfering with authentication
  10. Password contains special characters causing shell parsing issues

How to fix "fatal: Authentication failed for 'https://github.com/user/repo.git/'"

1Generate a Personal Access Token on GitHub

GitHub and many other Git hosting services no longer accept passwords for HTTPS authentication. You need to create a Personal Access Token (PAT):

For GitHub:
1. Go to [github.com/settings/tokens](https://github.com/settings/tokens)
2. Click Generate new token > Generate new token (classic)
3. Give it a descriptive name (e.g., "Development laptop")
4. Set an expiration date (or "No expiration" for convenience, though less secure)
5. Select scopes:
- repo - Full control of private repositories (required for push/pull)
- workflow - If you need to update GitHub Actions workflows
6. Click Generate token and copy it immediately (you won't see it again!)

Use the token as your password:

bash
git push origin main
# When prompted for password, paste your Personal Access Token

For GitLab: Settings > Access Tokens > Add new token

For Bitbucket: Personal Settings > App passwords > Create app password

2Clear cached credentials from your system

Old passwords or tokens may be cached in your operating system's credential manager. Clear them to force Git to prompt for new credentials:

On Windows (Credential Manager):

powershell
# Open Credential Manager
control /name Microsoft.CredentialManager

# Or via command line - list credentials
cmdkey /list

# Delete GitHub credentials
cmdkey /delete:git:https://github.com

Alternatively:
1. Open Control Panel > Credential Manager > Windows Credentials
2. Find entries starting with git:https://github.com
3. Click the entry and select Remove

On macOS (Keychain):

bash
# Delete Git credentials from Keychain
git credential-osxkeychain erase
host=github.com
protocol=https
# Press Enter twice

# Or use Keychain Access app to find and delete "github.com" entries

On Linux (credential helper):

bash
# Check what credential helper is configured
git config --global credential.helper

# If using 'store' (plain text file)
rm ~/.git-credentials

# If using 'cache'
git credential-cache exit

# If using GNOME Keyring or libsecret
# Open Seahorse (Passwords and Keys) and remove GitHub entries

After clearing, try your Git operation again - you'll be prompted for credentials.

3Configure Git to cache your new credentials

After generating a new token, configure Git to remember it so you don't have to enter it repeatedly:

Using Git Credential Manager (Recommended):

bash
# Install Git Credential Manager (if not already installed)
# On Windows: comes with Git for Windows
# On macOS: brew install git-credential-manager
# On Linux: see https://github.com/git-ecosystem/git-credential-manager

# Configure Git to use it
git config --global credential.helper manager

Simple credential caching:

bash
# Cache credentials in memory for 1 hour (3600 seconds)
git config --global credential.helper 'cache --timeout=3600'

# Or store permanently in a plain text file (less secure)
git config --global credential.helper store

macOS Keychain:

bash
git config --global credential.helper osxkeychain

Now when you enter your username and Personal Access Token, they'll be saved for future use.

4Switch from HTTPS to SSH authentication

SSH authentication is often more reliable and doesn't require tokens. Here's how to set it up:

Step 1: Check for existing SSH keys:

bash
ls -la ~/.ssh
# Look for id_ed25519.pub or id_rsa.pub

Step 2: Generate a new SSH key (if needed):

bash
ssh-keygen -t ed25519 -C "your_email@example.com"
# Press Enter to accept default location
# Enter a passphrase (optional but recommended)

Step 3: Add the SSH key to your SSH agent:

bash
# Start the SSH agent
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_ed25519

Step 4: Add the public key to GitHub:

bash
# Copy your public key
cat ~/.ssh/id_ed25519.pub
# Copy the output

1. Go to [github.com/settings/keys](https://github.com/settings/keys)
2. Click New SSH key
3. Paste your public key and save

Step 5: Change your remote URL to SSH:

bash
# Check current remote
git remote -v

# Change from HTTPS to SSH
git remote set-url origin git@github.com:username/repo.git

# Test the connection
ssh -T git@github.com
5Store credentials in the remote URL (for automation)

For CI/CD pipelines or automated scripts, you can embed credentials in the URL (use secrets management in production):

bash
# Set remote with token embedded (for automation only)
git remote set-url origin https://USERNAME:TOKEN@github.com/username/repo.git

# Clone with token
git clone https://USERNAME:TOKEN@github.com/username/repo.git

Important security considerations:
- Never commit URLs with tokens to version control
- Use CI/CD secret management (GitHub Actions secrets, GitLab CI variables)
- Tokens in URLs may appear in logs - be careful

Better approach for CI/CD:

bash
# Use environment variables
git config --global credential.helper '!f() { echo "password=$GIT_TOKEN"; }; f'

# Or configure inline
git -c "credential.helper=!f() { echo password=$GIT_TOKEN; }; f" push origin main
6Verify your username is correct

Authentication can fail if you're using the wrong username. Verify you're using the correct one:

For GitHub:
- Use your username, not your email address
- Your username is shown at [github.com/settings/profile](https://github.com/settings/profile)
- Usernames are case-insensitive but stored as lowercase

bash
# Check your configured username
git config --global user.name

# The username for authentication should match your GitHub username
# NOT your display name or email

Check repository access:

bash
# Ensure you have access to the repository
# Try opening the repository URL in a browser while logged in

For organization repositories:
- Ensure your account has been granted access to the organization
- Check if SSO is required: [github.com/settings/organizations](https://github.com/settings/organizations)
- You may need to authorize your token for SSO

7Update Git to the latest version

Older versions of Git may have bugs with authentication or lack support for modern credential managers:

Check your Git version:

bash
git --version

Update Git:

On Windows:

bash
# Using Git itself
git update-git-for-windows

# Or download from https://git-scm.com/download/win

On macOS:

bash
# Using Homebrew
brew upgrade git

# Or download from https://git-scm.com/download/mac

On Ubuntu/Debian:

bash
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

On Fedora/RHEL:

bash
sudo dnf update git

After updating, try your Git operation again.

Advanced notes

### Two-Factor Authentication (2FA) Considerations

When 2FA is enabled on your Git hosting account, regular passwords never work for HTTPS authentication. You must use:
- Personal Access Tokens (most common)
- SSH keys (recommended for daily development)
- GitHub CLI (gh auth login) which handles authentication automatically

### Git Credential Manager (GCM)

Git Credential Manager is the modern, cross-platform solution for credential storage:

bash
# Check if GCM is installed
git credential-manager --version

# Configure with OAuth (opens browser)
git credential-manager configure

# GCM supports:
# - GitHub (with OAuth device flow)
# - Azure DevOps
# - Bitbucket
# - GitLab

### Debugging Authentication

bash
# Enable Git credential debugging
GIT_TRACE=1 git push origin main

# More detailed credential debugging
GIT_CURL_VERBOSE=1 git push origin main

# Check credential helper configuration
git config --list --show-origin | grep credential

### Corporate Environments

If you're behind a corporate proxy:

bash
# Configure proxy for Git
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy https://proxy.company.com:8080

# If proxy requires authentication
git config --global http.proxy http://username:password@proxy.company.com:8080

### GitHub CLI Alternative

The GitHub CLI (gh) can handle authentication more seamlessly:

bash
# Install GitHub CLI
# brew install gh (macOS)
# winget install GitHub.cli (Windows)

# Authenticate (opens browser)
gh auth login

# Clone repositories
gh repo clone username/repo

# The CLI configures Git credentials automatically

### Fine-Grained Personal Access Tokens

GitHub now offers fine-grained PATs with more granular permissions:

1. Go to [github.com/settings/tokens?type=beta](https://github.com/settings/tokens?type=beta)
2. Select specific repositories
3. Choose only the permissions you need
4. Set an expiration date

These are more secure than classic tokens as they limit potential damage if compromised.

### Troubleshooting Windows Credential Manager Issues

If authentication keeps failing on Windows despite correct credentials:

powershell
# Reset Git credential manager
git credential-manager unconfigure
git credential-manager configure

# Or reinstall Git for Windows with GCM

### SSH Agent Forwarding

For accessing repositories from remote servers:

bash
# Add to ~/.ssh/config
Host github.com
    ForwardAgent yes

# Connect to server with agent forwarding
ssh -A user@server

Frequently asked questions

What does "fatal: Authentication failed for 'https://github.com/user/repo.git/'" mean?
This error indicates that Git's attempt to authenticate with the remote repository (typically GitHub, GitLab, or Bitbucket) was rejected. The remote server could not verify your identity using the credentials provided. Since August 2021, GitHub no longer accepts password authentication for Git operations over HTTPS.
How do I fix "fatal: Authentication failed for 'https://github.com/user/repo.git/'"?
The 'Authentication failed' error occurs when Git cannot verify your credentials with the remote repository. This typically happens because GitHub no longer accepts password authentication for HTTPS, requiring you to use a Personal Access Token or switch to SSH authentication.
What causes "fatal: Authentication failed for 'https://github.com/user/repo.git/'"?
Using password instead of Personal Access Token (PAT) with GitHub Personal Access Token has expired or been revoked Two-factor authentication (2FA) enabled but using password
Is the "fatal: Authentication failed for 'https://github.com/user/repo.git/'" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading