Background/Situation
Git run from the IDE does not see your WSL shell setup. A hook fails with executable file not found in $PATH, or an SSH key set up in an init script is missing so push and fetch cannot authenticate. The same command works in a WSL terminal.
Question
Why does git started from the IDE ignore the PATH and other variables from my WSL shell configuration?
Answer
Git runs hooks in a non-interactive shell, and ~/.bashrc exits early in that case:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Anything below that line, including your PATH, is skipped. A terminal is interactive and runs the whole file. That is the difference.
The IDE runs git through a login shell, which reads ~/.profile and ~/.bash_profile, but not ~/.bashrc.
Fix
Move PATH and any related exports from ~/.bashrc to ~/.profile:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
Then restart the IDE. The WSL environment is captured once, so a running IDE will not pick up the edit.
If ~/.bash_profile exists, bash reads it instead of ~/.profile, so put the exports there. And tools such as nvm, pyenv and mise install a whole init block into .bashrc: move the block, not just the PATH line.
If git still ignores ~/.profile
On older versions git runs in a non-login shell. Enable the registry key git.wsl.exe.executable.login.shell: press Shift twice, type Registry..., enable the key, restart the IDE. This is the IDE registry, not the Windows one.
Side effects
Init scripts must not print anything and must not change directory. Their output is parsed as git output, and a cd causes a "not a git repository" error.
Comments
0 comments
Please sign in to leave a comment.