Using GitHub HTTPS Credentials in WSL 2

Published on November 12, 2019

Windows Subsystem for Linux v2 is a huge new feature in Windows 10 that really changes the game for developers using web and backend technologies traditionally confined to *nix, or even worse, shuddermacOS! 😱

WSL really is the best of both worlds - you can use Linux software, and play Overwatch; who can complain?

Git Push + WSL = 🔪

But it’s not all roses, there are a few annoying integration caveats, but here’s how to solve at least one of them. Trying to git push to GitHub Just Works when you install Git for Windows, but in Linux, it’s always a drag. Most Linux people use SSH remote URLs, but on WSL that’s fairly annoying because of how out-to-lunch SSH Agent is. Having to type in an SSH key password for every git push gets old real quick.

So, let’s use the Windows credential provider, in WSL2!

Use the Windows Git Credential Provider in WSL

So, here’s how to make it work:

  1. Install Git for Windows
  2. In Windows-land, clone any private repo - this will pop up a GitHub dialog allowing you to log in (including handling 2FA correctly - you have 2FA enabled right? Right???).
  3. In your WSL distro, run sudo nano /usr/bin/git-credential-manager, then type this in:
#!/bin/sh
exec /mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe $@
  1. Run sudo chmod +x /usr/bin/git-credential-manager
  2. Now, open up your .gitconfig and add the following lines:
[credential]
helper = manager

And there you have it! Make sure you clone all your repos with https:// URLs (Pro-Tip: you can just use the URL to the repo, no need for .git) or re-configure them via git remote set-url, and you’ll be pushing and pulling, annoyance free.


Anaïs Betts

Written by Anaïs [a.na'is] Betts, who lives in San Francisco.

Twitter LogoCopyright 2018 Anaïs BettsGitHub Logo