Introduction
Setting up Git correctly on both Windows and WSL is essential for a smooth development workflow, especially in environments where you switch between the two.
This guide ensures
- Consistency – Your Git configuration and credentials work the same way in Windows and WSL, avoiding conflicts or repeated prompts.
- Security – By using Git Credential Manager (GCM) from Windows inside WSL, you get secure token storage without duplicating credentials.
- Efficiency – No need to manage separate credential helpers or manually sync
.gitconfigfiles between systems.
Follow these steps to install Git, configure it properly, and enable seamless authentication across both environments.
Git for Windows Setup
Note
These commands all need to run in Windows PowerShell.
1. Install Git for Windows. Git for Windows can be installed with the following command
winget install -e --id Git.Git --source=winget
Tip
If you need Git LFS, also run the following command:
winget install -e --id GitHub.GitLFS --source=winget2. Verify installation of Git for Windows (including Git Credentials Manager) with the following command
git --version; git credential-manager --version3. Set your Git email and username
Tip
If you are using GitHub, you can use your GitHub username and the “no-reply” email address from GitHub Email settings.
$env:GIT_EMAIL = "your-git-email"$env:GIT_USER = "your-git-username"4. Run the following commands to set initial settings for .gitconfig
Tip
These settings help avoid common git warnings.
git config --global color.ui "auto"
git config --global init.defaultBranch "main"
git config --global user.email "$env:GIT_EMAIL"
git config --global user.name "$env:GIT_USER"Git on WSL Setup
Note
These commands all need to run in WSL.
1. Install git and git-lfs packages. On Debian/Ubuntu
sudo apt-get update && sudo apt-get install git git-lfs2. Verify installation of Git and Git LFS
git --version && git lfs --version3. Copy your existing .gitconfig file from Windows
cp "$(wslpath -a "$(cmd.exe /c "<nul set /p x=%USERPROFILE%\.gitconfig")")" "${HOME}/.gitconfig"4. Configure Git Credentials Manager
git config --global credential.helper "$(wslpath -a "$(powershell.exe -NoProfile -Command "Write-Host -NoNewline (Join-Path ((Get-Item (git --exec-path)).Parent.Parent.FullName) 'bin\git-credential-manager.exe')")")"Featured image by Gabriel Heinzer on Unsplash.





