Git Clone from GitHub over https with two-factor authentication
It generally comes to mind that you have set up two-factor authentication, after a few password trials and maybe a password reset. So, how can we git clone a private repository using two-factor authentication? It is simple, using access tokens.
How to Authenticate Git using Access Tokens
- Go to https://github.com/settings/tokens
- Click Generate New Token button on top right.
- Give your token a descriptive name.
- Set all required permissions for the token.
- Click Generate token button at the bottom.
- Copy the generated token to a safe place.
- Use this token instead of password when you use git clone.
Wow, it works!
To everyone struggling, what worked for me was creating personal access token and then using it as a username AND password (in the prompt that opened).
As per @Nitsew's answer, Create your personal access token and use your token as your username and enter with blank password.
Later you won't need any credentials to access all your private repo(s).
Updates 2021: (It worked for my M1 Mac)
Create new Personal Access Tokens (Tick the appropriate boxes to grant permissions).
Use GitHub username
and password as your Personal Access Tokens
Find out how to fix this here:
https://github.com/blog/1614-two-factor-authentication#how-does-it-work-for-command-line-git
How does it work for command-line Git?
If you are using SSH for Git authentication, rest easy: you don't need to do anything. If you are using HTTPS Git, instead of entering your password, enter a personal access token. These can be created by going to your personal access tokens page.