GitHub Error: Authentication Failed from the Command Line

When setting up a 2 Factory Authentication in GitHub you might hit a wall when trying to clone or push changes to your repository. At least thats what happend to me.

Once I tried to checkout a new repository I got an authentication error which was kind of supprising.

PS \source\repos> git clone https://github.com/youruser/yourRepository.git
Cloning into 'yourRepository'...
Username for 'https://github.com': yourUsername
Password for 'https://yourUsername@github.com': password
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/youruser/yourRepository.git/'

After digging around I found that I need to create an personal access token to get authenticated.

Also to note in windows they have implemented an nice solution that you get an “credential prompt” but if you close it you will still get stuck with “authentication failed” error.

How to authenticate with GitHub when 2FA is setup

  1. Login to GitHub and go to our Settings

  1. Select Developer settings

  1. Next select Personal access token

  1. Now click on the button Generate new token . Choose the scope you thing you think are needed. Make sure you copy the Personal access token as soon as it gets generated otherwise you won’t be able to see it again and need to generate a new one.

  1. Now that you have the token generated try to checkout or push your changes to repository but in the password field use the generated token.