Repository navigation
Description
I either have to add C:/Program Files/Git/bin to PATH manually using Windows environment variables, or alternatively I had to install Git for Windows using something other than the recommended setting:

Recommended setting when installing Git for Windows:
- "Git from the command line and also from 3rd-party software"
Necessary setting for husky / GitHub Desktop compatibility:
- "Use Git and optional Unix tools from the command prompt."
Of course, the latter simply makes a similar PATH change automatically for me, specifically by adding the following to the PATH in my system variables:
C:\Program Files\Git\cmd
C:\Program Files\Git\mingw64\bin
C:\Program Files\Git\usr\bin
This is basically a known issue, in that GitHub Desktop doesn't package Git for Windows and thereby doesn't directly support running node via bash, just sh: #228 (comment)
Indeed, that particular bug report resulted in @typicode/husky using just sh internally, per desktop/desktop#3860 (comment)
That means that a pre-commit husky script that doesn't rely on node or npm will work without requiring bash in PATH for GitHub Desktop users on Windows:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
notepad
However, the majority of husky hooks are going to be more along the lines of @okonet/lint-staged
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
It would seem more reasonable for husky to include a "Windows compatibility" section in the docs than to ask GitHub Desktop to bundle all of Git for Windows into their Electron app.
That section could read simply:
Husky Hooks and Windows Compatibility with GitHub Desktop
If you're using a third-party GUI like GitHub Desktop for managing Git commits in Windows, you may get an error that `bash` is a command not found.
This error commonly occurs when trying to run package manager based scripts, like the "npx lint-staged" command, as part of your husky pre-commit hooks.
To fix this error, you'll need to add the Git for Windows tools to your PATH by either:
1. Choosing "Use Git and optional Unix tools from the command prompt" in the Git for Windows installer, or
2. Adding "C:/Program Files/Git/bin" [or your appropriate installation location] to the PATH manually as an Environmental Variable in Windows.
Similar issues have been reported for the Node Version Manager program nvm on *nix systems, but those issues are addressed in the "command not found" section of the docs, which explains using a ~/.huskyrc file.

Activity
DoctorDerek commentedon Apr 16, 2021
I'm going to close the issue because I can't quite reproduce the compatibility problems II was having to verify.
I had been seeing
command not founderror 127 citingbashin GitHub Desktop when trying to run thenpx lint-stagedpre-commit hook, but I'm not seeing it now.It may have been associated with NVM for Windows, which doesn't support .nvrmc files; while trying to debug this issue I uninstalled that and installed latest node (15.14.0) and npm (7.10.0).
Now I can run the husky pre-commit hooks using the "recommended settings" when installing Git for Windows (which do in fact include
C:\Program Files\Git\binas a user variable andC:\Program Files\Git\cmdas a system variable but neitherC:\Program Files\Git\mingw64\binnorC:\Program Files\Git\usr\binas system variables).So there was definitely a transient PATH issue, probably leftover from the nvm installation.
DindoLeonard commentedon Nov 11, 2021
Thanks man! really helped me a lot.
configured commit hooks on ESlint and prettier