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:

bash
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.helper shows 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 push and git fetch require authentication each time

Common Causes

  • WSL2 cannot access Windows Credential Manager directly
  • git-credential-manager-core not 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. 1.Install Git Credential Manager in WSL2:
  2. 2.```bash
  3. 3.# Download and install GCM
  4. 4.sudo apt update
  5. 5.sudo apt install gpg
  6. 6.wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/packages.microsoft.gpg
  7. 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. 8.sudo apt update
  9. 9.sudo apt install microsoft-git-credential-manager
  10. 10.`
  11. 11.Configure Git to use the credential manager:
  12. 12.```bash
  13. 13.git config --global credential.helper /usr/share/microsoft-git-credential-manager/git-credential-manager-core
  14. 14.`
  15. 15.Or if GCM is in your PATH:
  16. 16.```bash
  17. 17.git config --global credential.helper manager-core
  18. 18.`
  19. 19.Enable WSL2 interop to use Windows Git's credential helper:
  20. 20.```bash
  21. 21.git config --global credential.helper "/mnt/c/Program\\ Files/Git/mingw64/bin/git-credential-manager-core.exe"
  22. 22.`
  23. 23.Alternative: Use a personal access token directly:
  24. 24.```bash
  25. 25.git config --global credential.helper 'store --file ~/.git-credentials'
  26. 26.# First push will prompt for credentials, then they are stored
  27. 27.echo "https://<TOKEN>@github.com" > ~/.git-credentials
  28. 28.chmod 600 ~/.git-credentials
  29. 29.`
  30. 30.Verify credential helper is working:
  31. 31.```bash
  32. 32.git credential-manager-core diagnose
  33. 33.# Or test with a fetch
  34. 34.git fetch origin
  35. 35.# Should not prompt for credentials
  36. 36.`

Prevention

  • Install GCM as part of your WSL2 development environment setup
  • Use git config --global credential.helper manager-core as 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 ~/.gitconfig in 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