Zit Seng's Blog

A Singaporean's technology and lifestyle blog

WSL with Git Credential Manager for Windows

I’ve been using Windows for much of my work now. One of the things I struggled with was about supplying my GitHub credentials to git when used in Windows Subsystem for Linux. The solution isn’t complicated, but it just isn’t well documented.

So here’s a short how-to, for my own reference if I ever need to setup this up again, and anyone else trying to do the same thing. This is for using git in Windows Subsystem for Linux, in a distribution like Ubuntu. There are other tutorials about using git in cmd.exe, or in a Git Bash, or the like. I’ve included bit extras about GPG signing of commits.

First, go get Microsoft’s Git Credential Manager for Windows. It’s on GitHub, look further down for the installer executable. Install that. The defaults to all the install questions are just fine.

Then, in your WSL shell, configure git like so:

git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe "

(The above is just one line, of course.)

That’s basically it. The next time you try to git pull (or whatever) from GitHub, you’ll be properly prompted in a GUI dialog box for your credentials. It will even cleverly handle 2FA logins automatically, obtaining a Personal Access Token on your behalf.

Subsequently, you won’t have to keep authenticating to GitHub anymore. GitHub’s official guide at https://help.github.com/en/articles/adding-a-new-gpg-key-to-your-github-account is excellent.

Just know that if you added a passphrase for your GPG key, you may need to set the GPG_TTY environment variable as such:

$ export GPG_TTY=$(tty)

You should put that in your .bashrc.

Then, you can also tell git you want your commits signed all the time by default:

$ git config --global commit.gpgsign true

This should make your git work so much easier.

Leave a Reply

Your email address will not be published. Required fields are marked *

View Comment Policy