jesseduffield / jesseduffield/lazygit
Cannot change directory when using MSYS2/Cygwin git.exe on Windows: "The system cannot find the path specified"
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
---
**What happened:**
I installed `lazygit` via Chocolatey on Windows(and also binary release). When I try to open `lazygit` inside a Git repository, I encounter the following error:
```text
2026/06/08 14:54:26 An error occurred! Please create an issue at: https://github.com/jesseduffield/lazygit/issues
*fs.PathError chdir /cygdrive/h/Repo/C2_py: The system cannot find the path specified.
```
**Root cause analysis:**
After investigation, I found that the issue occurs when `lazygit` is using a `git.exe` that is **NOT** the standard one from `C:\Program Files\Git\*`, but rather:
- An MSYS2 git (`C:\msys64\mingw64\bin\git.exe`)
- A Cygwin git (`C:\Apps\Terminals\cygwin64\bin\git.exe`)
- Any Git distribution based on MSYS2/Cygwin
The problem is a **path format mismatch**:
| Component | Path format expected |
|-----------|---------------------|
| MSYS2/Cygwin git.exe | Unix-like: `/cygdrive/h/Repo/C2_py` |
| Lazygit (native Windows app) | Windows format: `H:\Repo\C2_py` |
When `lazygit` passes a Windows-format path (`H:\Repo\C2_py`) to an MSYS2-based `git.exe`, Git fails with `cannot find the path specified` because it doesn't understand the Windows path format.
**What I already tried:**
1. Running `git config --global --add safe.directory H:/Repo/C2_py` → Does NOT resolve the issue
2. The solution proposed in the initial error message (`safe.directory`) only addresses the "dubious ownership" problem, not this path conversion issue
3. After the first error (dubious ownership) is fixed, this second error (path not found) appears
**WORKING SOLUTION (for users facing this issue):**
Remove the MSYS2/Cygwin Git path from your system `PATH` environment variable. For example, remove:
- `C:\Apps\Terminals\cygwin64\bin\`
- `C:\msys64\mingw64\bin\`
- or any similar MSYS2/Cygwin-based Git path
**After removing this path from `PATH`, the issue is completely resolved** and `lazygit` starts working normally because it will automatically use the correct Git for Windows from `C:\Program Files\Git\cmd\git.exe`.
**Environment:**
- OS: Windows (latest)
- Lazygit installed via: Chocolatey (`choco install lazygit`) and binary release
- Git version that was causing the issue: MSYS2/Cygwin Git (e.g., `C:\Apps\Terminals\cygwin64\bin\git.exe`)
- Repository path: `H:\Repo\C2_py`
**Expected behavior:**
`lazygit` should work regardless of which `git.exe` is used, as long as it's a valid Git executable. Currently, it only works with the standard Git for Windows (`C:\Program Files\Git\cmd\git.exe`).
**Why this matters for development:**
While users have a workaround (removing MSYS2/Cygwin paths from `PATH`), this is not ideal because:
1. Users may legitimately need MSYS2/Cygwin tools for other purposes
2. The failure is silent and confusing - the error message points to a path issue, not a PATH configuration issue
3. Many Windows developers have multiple Git installations without realizing the conflict
**Additional context:**
This issue has been acknowledged in the MSYS2 package repository (Issue #21303), where the maintainer noted that this appears to be an MSYS2 path transformation bug rather than a pure `lazygit` bug.
Similar path conversion issues have been discussed in Stack Overflow, where users working with MSYS2/Cygwin git from non-MSYS2 environments face the same problem.
**Possible solution directions for the `lazygit` team:**
1. **Detect MSYS2/Cygwin Git:** Lazygit could detect if the available `git.exe` is MSYS2/Cygwin-based and either warn the user or handle path conversion accordingly
2. **Prefer standard Git for Windows:** Lazygit could prioritize `git.exe` from `C:\Program Files\Git\` over MSYS2 versions when both are available
3. **Better error message:** When this error occurs, Lazygit could suggest that the user check their PATH for conflicting Git installations
4. **Path conversion fallback:** When encountering this error, Lazygit could retry with converted paths (e.g., using `cygpath -m` equivalent if available)
**Workaround for users (to be documented):**
Ensure that `C:\Program Files\Git\cmd` appears **before** any MSYS2/Cygwin paths in the system `PATH` environment variable. **Better yet, remove MSYS2/Cygwin Git paths from PATH entirely** if you don't specifically need them for other purposes. After doing this, `lazygit` will work correctly.
Wishing you health and success.
davood yahay
----
Contributor guide
Assessment
This issue has not been assessed yet.