Windows & Git Bash: Bash PATH to read Windows %PATH% system variable

An msysgit git bash session uses the script share/WinGit/Git Bash.vbs, which doesn't access or modify the environment variable PATH (like it would in this unrelated vbs script, for instance)

A git bash session will simply add in front of your current PATH:

.:/usr/local/bin:/mingw/bin:/bin:

It is possible that the mingw session packaged with msysgit won't consider a bin from another mingw installation: you can check it by setting another (simpler) directory to your PATH and see if it is still visible in your git bash session. If not, then it is a more general issue which concerns all directories that you would add to the PATH.


Here's my small workaround for a similar problem (MSYS2 bash on Windows 10).

The idea is to convert the required paths to Unix-style paths and append them to bash $PATH, all done in .bashrc.

Do not append required paths to Win PATH. Instead create a new env var in Windows, like MSYS2_WINPATH, and append all the semicolon-separated Windows path directories to this variable. Append %MSYS2_WINPATH% to %PATH%.

Now insert this in your .bashrc -

################################## Construct PATH variable ##################################

winpath=$(echo $MSYS2_WINPATH | tr ";" "\n" | sed -e 's/\\/\\\\/g' | xargs -I {} cygpath -u {})
unixpath=''

# Set delimiter to new line
IFS=$'\n'

for pth in $winpath; do unixpath+=$(echo $pth)":"; done

export PATH=$(echo $PATH:$unixpath | sed -e 's/:$//g')
unset IFS
unset unixpath
unset winpath

################################# Constructed PATH variable #################################

If the PATH value would be too long after your user's PATH variable has been concatenated onto the environment PATH variable, Windows will silently fail to concatenate the user PATH variable.

This can easily happen after new software is installed and adds something to PATH, thereby breaking existing installed software. Windows fail!

The best fix is to edit one of the PATH variables in the Control Panel and remove entries you don't need. Then open a new CMD window and see if all entries are shown in "echo %PATH%".