Introduction
Git credential helpers store authentication tokens so you do not need to re-enter them for every push or fetch. In WSL2 (Windows Subsystem for Linux 2), the credential helper often fails to store or retrieve tokens due to the separation between the Linux and Windows environments:
git push
# Username for 'https://github.com':
# Password for 'https://user@github.com':
# (Prompts every time instead of using stored credentials)Symptoms
- Git prompts for username and password on every remote operation
git config --get credential.helpershows a helper but it does not work- Token stored in Windows Credential Manager is not accessible from WSL2
- Credential helper works on native Linux but not in WSL2
git pushandgit fetchrequire authentication each time
Common Causes
- WSL2 cannot access Windows Credential Manager directly
git-credential-manager-corenot installed in WSL2- Credential helper configured for Windows but not for the WSL2 Linux distribution
- D-Bus or keyring service not running in WSL2
- Git in WSL2 using a different credential helper than Windows Git
Step-by-Step Fix
- 1.Install Git Credential Manager in WSL2:
- 2.```bash
- 3.# Download and install GCM
- 4.sudo apt update
- 5.sudo apt install gpg
- 6.wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/packages.microsoft.gpg
- 7.sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
- 8.sudo apt update
- 9.sudo apt install microsoft-git-credential-manager
- 10.
` - 11.Configure Git to use the credential manager:
- 12.```bash
- 13.git config --global credential.helper /usr/share/microsoft-git-credential-manager/git-credential-manager-core
- 14.
` - 15.Or if GCM is in your PATH:
- 16.```bash
- 17.git config --global credential.helper manager-core
- 18.
` - 19.Enable WSL2 interop to use Windows Git's credential helper:
- 20.```bash
- 21.git config --global credential.helper "/mnt/c/Program\\ Files/Git/mingw64/bin/git-credential-manager-core.exe"
- 22.
` - 23.Alternative: Use a personal access token directly:
- 24.```bash
- 25.git config --global credential.helper 'store --file ~/.git-credentials'
- 26.# First push will prompt for credentials, then they are stored
- 27.echo "https://<TOKEN>@github.com" > ~/.git-credentials
- 28.chmod 600 ~/.git-credentials
- 29.
` - 30.Verify credential helper is working:
- 31.```bash
- 32.git credential-manager-core diagnose
- 33.# Or test with a fetch
- 34.git fetch origin
- 35.# Should not prompt for credentials
- 36.
`
Prevention
- Install GCM as part of your WSL2 development environment setup
- Use
git config --global credential.helper manager-coreas the default for WSL2 - Document the credential setup process in your WSL2 development guide
- Prefer SSH keys over HTTPS + credential helpers for Git authentication:
- ```bash
- ssh-keygen -t ed25519 -C "your-email@example.com"
- # Add the public key to GitHub/GitLab
- git remote set-url origin git@github.com:org/repo.git
`- Test credential helper after WSL2 updates as interop behavior may change
- Keep
~/.gitconfigin version control (without tokens) for reproducible setup - Use GitHub CLI (
gh auth login) which handles WSL2 credential storage automatically - Monitor WSL2 version updates for known credential helper issues