Skip to content

git push authentication failed: 3 Quick Fixes for SSH & HTTPS

5 min read

If you’re a developer, chances are you’ve run into the dreaded message:

bash

It usually appears when you try to run:

bash

This error can be frustrating, especially when it blocks your ability to push code to your remote repository. Whether you’re using SSH or HTTPS, this guide will help you fix the git push authentication failed error with 3 quick and effective solutions.


✅ Why Does git push authentication failed Happen?

Git requires authentication to ensure only authorized users can push changes to a repository. The error usually stems from:

  • Expired or invalid credentials
  • SSH key mismatch or misconfiguration
  • Personal Access Token (PAT) not used correctly
  • Changes in authentication method (e.g., GitHub disabling password authentication)

Let’s look at how to fix this fast.


🔧 Fix 1: Use SSH Instead of HTTPS (or Fix Your SSH Key)
🧠 Why it Works

If you’ve cloned your repo using HTTPS and you’re asked to log in every time — or you get an authentication failure — switching to SSH can save you a lot of hassle.

🔄 Steps to Fix
  1. Check if you already have an SSH key:

bash

Look for files like id_rsa or id_ed25519.

  1. If you don’t have one, generate an SSH key:

bash

When prompted, press Enter to accept defaults.

  1. Add the key to your SSH agent:

bash

  1. Copy your public key and add it to GitHub/GitLab:

bash

Then go to GitHub > Settings > SSH and GPG Keys > New SSH Key, and paste it there.

  1. Switch your remote from HTTPS to SSH:

bash

  1. Test the connection:

bash

If it says you’re authenticated, you’re good to go.


🔧 Fix 2: Use a Personal Access Token (For HTTPS Authentication)
🧠 Why it Works

GitHub and other platforms no longer support password-based authentication over HTTPS. Instead, they require a Personal Access Token (PAT).

🔄 Steps to Fix
  1. Go to your GitHub settings:
    • Profile > Settings > Developer Settings > Personal Access Tokens
  2. Click on “Generate new token (Classic)”
  3. Give it a name, set expiration, and select scopes:
    • At minimum, check: repo scope
    • Generate the token and copy it (you won’t see it again!)
  4. Update your Git credentials with the token: When you push again, and Git asks for a username and password:
    • Username: your GitHub username
    • Password: paste the PAT you just generated
  5. (Optional) Store credentials using a helper:

bash

Or for a more permanent store:

bash

Then push again:

bash


🔧 Fix 3: Re-authenticate or Clear Git Credentials
🧠 Why it Works

Sometimes cached or corrupted credentials cause problems — especially if you recently changed your password or token.

🔄 Steps to Fix
For macOS (Keychain Access):
  1. Open Keychain Access
  2. Search for git or github.com
  3. Delete old credentials

For Windows:

  1. Open Credential Manager
  2. Go to Windows Credentials
  3. Find entries for GitHub or Git and remove them

For Linux or CLI Users:

You can also manually clear stored credentials:

bash

Or use:

bash

After clearing, try pushing again:

bash

It will prompt you to enter your new credentials or token.


🧪 Bonus: Check Your Remote URL Format

You can always check your current remote URL using:

bash

Make sure it’s using the correct format:

  • SSH: git@github.com:username/repo.git
  • HTTPS: https://github.com/username/repo.git

Use this to troubleshoot if you’re accidentally mixing protocols.


🛠️ When to Use SSH vs HTTPS

Choosing between SSH and HTTPS depends on your workflow and environment. SSH is generally preferred for frequent contributors because it’s more secure and avoids having to enter your credentials repeatedly. Once configured, SSH keys make authentication seamless. On the other hand, HTTPS is easier for beginners and works better behind strict corporate firewalls, but it now requires personal access tokens for authentication, which adds a bit of setup overhead.


🧩 Common Pitfall: Cloning with One Protocol, Pushing with Another

A sneaky reason for git push authentication failed is accidentally mixing SSH and HTTPS in the same project. You might clone using HTTPS, then try pushing with SSH—or vice versa—without realizing it. This causes mismatches during authentication. Always double-check your remote origin with git remote -v and make sure you’re using one consistent protocol across all operations in your repository.


🧪 Advanced Tip: Use .gitconfig to Set Protocols Globally

For users managing multiple repositories, setting global preferences in your .gitconfig file can save time. For example, you can force Git to always use SSH by setting the URL rewrite rule globally:

bash

This ensures any future clones or remotes default to SSH even if you accidentally paste an HTTPS URL. It’s a small trick that can prevent authentication issues from popping up in the future.



🧠 Final Thoughts

The git push authentication failed error is common, but luckily, the fixes are straightforward. Whether you prefer SSH or HTTPS, the key is to:

  • Use SSH keys properly
  • Use a Personal Access Token (PAT) for HTTPS
  • Clear and re-authenticate your Git credentials when things break

With these three fixes, you’ll be back to pushing code in no time.