If you are using two-factor authentication on your Github account, chances are that you will be puzzled when you try to git clone your private repository from GitHub. Because it won't ask you two-factor authentication input, instead it will give you an error message like this:
C:\Users\you\projects>git clone https://github.com/you/private-repo Cloning into 'private-repo'... Username for 'https://github.com': <your username> Password for 'https://<your username>@github.com': remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/you/private-repo/' C:\Users\you\projects>
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.
- Voila, it works!
So, this is how to git clone a private repo with 2fa (two-factor authentication). I hope you found this tip useful. Cheers!