Visual Studio Code + Git 2FA


On my mac, my application development environment is Visual Studio Code (VSC) and GitHub.  My GitHub account has been enabled with 2 Factor Authentication, and each time I change code and make a commit, I’ve been finding that it fails due to the 2 factor security code missing (as I opted to have this sent to my mobile) when prompted for my username / password.    Having spent time to find a solution using Google etc., this post summarises how to setup VSC + GitHub correctly to work when 2 Factor Authentication is enabled on the GitHub account.

The key to success is to create a Personal Access Token (PAT) in GitHub, this is essentially a security token generated against your account that works like an ordinary OAuth token, and once generated should be used as the password in VSC when you try to make a commit and get the prompt for username / password, when this is used the first time, the VSC configuration is updated and you will now find that actions against your GitHub repo’s no longer cause security issues and fail.

To generate the PAT, log into your GitHub account, select Settings, then Developer Settings, then Personal Access Tokens.     You should now select the “Generate new token” button, enter a name for the PAT and ensure you tick the repo option for the scope, then save….  

VSC2FA

Enjoy the freedom this gives you to control your repos via VSC 🙂

 

Comments are closed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: