Script Valley
Developer Environment Setup (WSL, Terminal, VS Code)
Installing and Managing Development ToolsLesson 4.3

How to configure Git correctly in WSL2

git install, git config global user name and email, git config default branch, git credential helper for WSL2, SSH key generation, adding SSH key to GitHub

Configuring Git in WSL2

Git credential helper flow diagram

Git comes pre-installed in most WSL2 distros. Configuration lives in ~/.gitconfig and must be set before your first commit.

Initial global configuration

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"

SSH key setup for GitHub

ssh-keygen -t ed25519 -C "you@example.com"
# Press Enter for default location, set a passphrase

cat ~/.ssh/id_ed25519.pub
# Paste output into GitHub Settings > SSH and GPG keys

Test the connection

ssh -T git@github.com
# Hi username! You have successfully authenticated...

Windows Credential Manager integration (optional)

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

This requires Git for Windows to be installed on the Windows side. It stores HTTPS credentials so you are not prompted on every push.

Up next

How to install Docker Desktop and use it with WSL2

Sign in to track progress