After setting up 2 Factor Authentication on GitHub, I couldn’t push my remote repositories from the command line anymore.
When I tried to push a remote repo, the command line threw this error:
~ :> git push origin my-branch
Username for 'https://github.com': myusernamePassword for 'https://[email protected]': mypasswordremote: Invalid username or password.fatal: Authentication failed for 'https://github.com/my-repository’
The error stumped me — and made me vow that, when I did ultimately get to the bottom of it, I’d do my best to pay the knowledge forward.
How to Authenticate on GitHub with 2FA
Command line authentication requires a personal access token.
Go to Settings:
![Image for post](https://miro.medium.com/max/3952/1*msyCH1amQUU75QFbrhqvIA.png)
Then Developer Settings:
![Image for post](https://miro.medium.com/max/3920/1*m6EQSNjnkpYXZvoIf0TRrg.png)
Then Personal access tokens:
![Image for post](https://miro.medium.com/max/3832/1*jDRo0-poBXPd_WxONGBOXA.png)
Generate a new Personal Access Token. Make sure you copy the Personal Access Token as soon as it gets generated — you won’t be able to see it again!
![Image for post](https://miro.medium.com/max/3816/1*bi9qdbUZ9I2Q3uxGEND12Q.png)
Paste the Personal Access Token into the “Password” field when you authenticate via the command line.
![Image for post](https://miro.medium.com/max/2816/1*64UoBJrnazo8FZDJ4SGS8w.png)
GitHub has published official instructions for this flow here (though without glam screenshots…)