As an Amazon Associate, I earn from qualifying purchases.

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
Cloning into 'private-repo'...
Username for '': <your username>
Password for 'https://<your username>':
remote: Invalid username or password.
fatal: Authentication failed for ''


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

  1. Go to
  2. Click Generate New Token button on top right
  3. Give your token a descriptive name
  4. Set all required permissions for the token
  5. Click Generate token button at the bottom
  6. Copy the generated token to a safe place
  7. Use this token instead of password when you use git clone.
  8. 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!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More How To
Share Share Tweet