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.
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.
And now when pressing ‘OK’ you will be authorized to push changes to your repositories.