Git basic configuration after enabling GitHub 2FA

项月亮
1 min readJun 30, 2021

After enabling two-factor authentication for your github account, the lagacy password authentication is invalid with the following error, so your need to use token to enable a new auth way.

remote: Invalid username or password.
fatal: Authentication failed for '...'
  1. Generate a new token for your account( to replace your password in authentication)

Click your avatar in GitHub home page, Settings > Developer settings > Personal access tokens , and generate a new token according to the promot, if you already had a token, you can also use the old one.

2. Configure your basic auth info in your server or computer.

Enter a git project directory and update your username or email (you do not need to change your username or email, just enter the same as last time)

git config user.name '[ENTER YOUR USERNAME HERE]'

and then input a simple git command which needs authentication, like

git pull

then you should be asked to input your GitHub username and password

Username for 'https://www.github.com' :Password for '...(your project link)':

that’s all done, but if you want to store your GitHub credential to reduce the times you have to enter your password:

git config --global credential.helper store

--

--