I’m using WSL2 to manage my blog, but I noticed each time I went to run git push it was asking for my credentials again. Why wasn’t it remembering from last time? Turns out there’s ways of storing git credentials, but even better, you can share the credentials you already have in Windows.

As outlined in this Stack Overflow answer, assuming you have Git Credential Manager installed in Windows (and you probably do with a recent install of the Git command line tools), then run this in WSL2:

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

Note the extra escape to handle the space in Program Files. With that set, git push just worked.

Update 2022-07-08

See Git Credential Manager setup for newer instructions on how to do this.