Cover Image

Using GitHub with 2FA in Visual Studio Code

April 17, 2016 - Reading time: ~1 minute

Using two factor authentication to further secure your GitHub-account is good. But now you can't push your changes through your IDE by just using your username and password. All we get when entering our credentials are

remote: Anonymous access to user/repo.git denied.
fatal: Authentication failed for 'https://github.com/user/repo.git/'

Not good. So how can we authenticate from within our IDE when using 2FA? The solution is personal access tokens. So first generate a new token with a description and the scopes you need. To just be able to push changes you only need to select the 'repo'-scope.

PAT screenshot

Now generate the token and make sure you save it in a secure place, you can't recover the token again if you lose it. Back in Visual Studio Code, push your changes and in the credential helper dialog enter the access token as the username and leave the password field blank.

Git authentication screenshot

And now when pressing 'OK' you will be authorized to push changes to your repositories.