Two factor authentication is great but until recently I’ve had numerous problems getting it to work with repositories on GitHub. Happily I’ve found the easy way. This only applies to Windows users and only works over HTTPS, not SSH.

First install Chocolatey.

Now open a command line as an administrator and install two Chocolatey packages.

cinst git -y
cinst git-credential-manager-for-windows -y

That’s it. Git credential manager is where the magic happens. When you take an action on your repository, over HTTPS, you’ll be asked for your username, password and your two factor authentication code. Credential manager then automatically creates a personal access token with read/write permissions on that repository and stores the token. All subsequent git commands for the repository use the stored access token, no further authentication is required. Simple.