2FA give problems when pushing to GitHub
with 2FA you have to create a personal access token to use as a password when authenticating to GitHub on the command line with HTTPS URLs: https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled
or you can clone with ssh https://help.github.com/articles/which-remote-url-should-i-use/#cloning-with-ssh-urls (may also be useful: https://help.github.com/articles/generating-an-ssh-key/)
with 2FA you need to generate personal access token while pushing the code. That personal token will be used as a password while pushing the code to Github. You can see that how to create the personal access token from https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line. It will be used when you have clone the repo with http url. It will be working for all the repositories.
If you have cloned the through SSH then you can push your changing very easily without any changes in normal behavior after enabling the 2F authentication. For this you use SSH key passphrase as a password. First it requires you to create SSH key against your repository. You can generate SSH key from https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent It will be working only single repository only for that specific repsority again which this SSH key has been generated.
If you've cloned over https and want to keep using that, for whatever reason, you can edit .git/config
to include the personal access token generated per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.
A sample .git/config
entry:
[remote "<YOUR-REMOTE-NAME>"]
url = https://<YOUR-USERNAME>:<YOUR-TOKEN>@github.com/<etc your repo url>
This is putting your token key in this plain text file on your machine, which is bad, but if you need a quick hack to get things going, it works.
Cheers!
You have to generate an access token and use the access token instead the password. For example:
$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token
Doc: https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line