Repository navigation
Description
The problem
On Windows, with Load Git hook environment variables from shell enabled and the shell set to Windows PowerShell or PowerShell Core, the Git LFS pre-push hook fails on every push:
Running pre-push hook...
Error getting Git version: executable file not found in %PATH%
pre-push hook failed with code 2 after 0.47s
Root cause. getShellEnv in app/src/lib/hooks/get-shell-env.ts spawns the shell with an empty environment:
const child = spawn(shell, [...args, quoteCommand(printenvzPath)], {
env: {},
...When it is given an empty environment on Windows, Node/libuv adds only a fixed set of required variables (PATH, SYSTEMROOT, TEMP, USERPROFILE, ...), and PATHEXT is not one of them. PowerShell (both 5.1 and 7) starts without PATHEXT and sets it to just .CPL. printenvz captures that value and the hook runs with it. git-lfs (Go) resolves git through PATHEXT, so it looks only for git.CPL and never finds git.exe. The same problem breaks hooks that call .cmd shims such as npm or ts-node (#23154).
With Git Bash or Command Prompt, PATHEXT is not set at all. Go then falls back to its default extensions, and the hook works.
Release version
3.7.1-beta2 (x64); also seen on 3.6.12-beta2
Operating system
Windows 11 (10.0.26300), Git LFS 3.8.1, Git for Windows 2.56.1
Steps to reproduce the behavior
- Go to File → Options → Git → Hooks, enable "Load Git hook environment variables from shell" and choose Windows PowerShell (or PowerShell Core).
- Open a repository with the Git LFS hooks installed (
git lfs install;.git/hooks/pre-pushrunsgit lfs pre-push "$@"). - Commit and push.
- The "pre-push hook failed" dialog appears.
A simpler check that doesn't need LFS: a pre-push hook containing echo "PATHEXT=$PATHEXT" >&2; exit 1 should print PATHEXT=.CPL.
Log files
error: [ui] `git push --progress -- origin <branch>:<branch>` exited with an unexpected code: 1.
Running pre-push hook...
Error getting Git version: executable file not found in %PATH%
pre-push hook failed with code 2 after 0.47s
error: failed to push some refs to '<remote>'
Additional context
I reproduced this outside Desktop by replaying the getShellEnv + hooks-proxy flow with the same parameters. The replay spawns the shell with an empty environment and runs printenvz, sets GIT_EXEC_PATH from the system Git, and then runs git hook run pre-push with the bundled Git:
| Hook shell | Captured PATHEXT |
Result |
|---|---|---|
| Windows PowerShell | .CPL |
fails, exit 2 |
| PowerShell Core | .CPL |
fails, exit 2 |
PowerShell, default PATHEXT put back into the hook environment |
default list | passes |
| Git Bash | not set | passes |
| Command Prompt | not set | passes |
Possible fix: on Windows, pass the parent's PATHEXT when spawning the shell, for example env: __WIN32__ && process.env.PATHEXT ? { PATHEXT: process.env.PATHEXT } : {}. Another option is to restore PATHEXT from process.env when the loaded environment is missing it or contains only .CPL.
Workaround: choose Git Bash or Command Prompt as the hook shell.
Related: #23154 (same root cause; ts-node.cmd is not found).
Activity
desktop-triage commentedon Nov 27, 2026
Triage summary: This is a reproducible Windows bug affecting any user who selects PowerShell/PowerShell Core as the Git hooks shell and has a hook that resolves a
.cmd/extension-less executable viaPATHEXT(e.g., Git LFS,npm,ts-node); I'm requestingbug,priority-2, andwindowswith HIGH confidence, since the report includes precise repro steps, version info, error text, and a clear mechanism. This appears closely related to #23154 (same root cause,ts-node.cmdnot found) — not a duplicate to close, since that issue reports the symptom without diagnosing the cause, but both should likely be fixed together.Initial hypothesis
The reporter's analysis lines up with the current source:
getShellEnvinapp/src/lib/hooks/get-shell-env.ts(lines 33–39) spawns the configured hook shell withenv: {}, i.e. no inherited environment. On Windows,child_process.spawnwith an emptyenvcauses Node/libuv to populate only a minimal required set of variables; PowerShell then initializes its own session and setsPATHEXTto a degenerate value (.CPL) rather than the Windows default list (.COM;.EXE;.BAT;.CMD;...). Becauseprintenvzcaptures whateverPATHEXTexists in that shell session and the hook later runs with that captured environment, any subsequent lookup that depends onPATHEXTto resolve a non-.exeexecutable (Git LFS resolvinggit, ornpm/ts-node.cmdshims) fails with "executable file not found". Git Bash and cmd.exe apparently don't setPATHEXTat all in this scenario, letting Go/npm fall back to built-in default extensions, which is why only the PowerShell hook shells are affected. This is consistent with both this issue and #23154 and points at theenv: {}spawn option (or the missingPATHEXTrestoration before running hooks) as the next thing for a maintainer to verify.