Git Authentication Failure When Pushing to GitHub Repository

Enabling 2FA on a GitHub account requires a 2FA token to be used to authenticate. This article goes over some tips to workaround this issue.
Git Authentication Failure When Pushing to GitHub Repository

Problem

After enabled 2FA on my GitHub account, I received the following authentication failure while doing a git push to my branch:

Notice that the error states that support for password authentication was removed on January 13, 2024.

Solution

With 2FA (Two-Factor Authentication) enabled in your GitHub account, you will not be able to push via HTTPS using your account password. Instead you will need to provide your 2FA authentication code.

⚠️
Enabling 2FA on a GitHub account will require the use of a 2FA token to push to the repository.

A simple workaround is to switch from using HTTPS to SSH. You can do this by navigating to the .git/ directory and opening the config file. The image below displays the following modifications:

  • Comment out the HTTPS URL
  • Insert the SSH URL
  • Insert user section containing name and email

You can retrieve the SSH url from the GitHub repository, as shown below:

Additional Resource:

About the author

Arapi Tech

Networking + DevOps + Programming

Arapi Tech Blog

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Arapi Tech Blog.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.