Git Bash rewrites any argument that starts with a slash
An API path, a container path, a Kubernetes resource — anything beginning with a slash gets silently converted into a Windows filesystem path before the program is even started. Testing it with echo shows nothing wrong, because echo is one of the programs it does not affect.
The symptom
$ gh api /user
invalid API endpoint: "C:/Program Files/Git/user". Your shell might be
rewriting URL paths as filesystem paths. To avoid this, omit the leading
slash from the endpoint argument
The argument typed was /user. The program received C:/Program Files/Git/user. Nothing in between reported an error, and the shell printed no warning.
The GitHub CLI is unusually helpful here: it recognises its own mangled input and tells you what happened. Most programs do not. They receive a Windows path where a URL path, a container path or a resource name was meant, and fail with something that looks like your mistake.
Why echo will not show you this
The instinct is to check what the shell is passing:
$ /usr/bin/echo /user/repos
/user/repos
Unchanged. No conversion, nothing suspicious — so the problem must be elsewhere. It is not.
The diagnostic you reach for is one of the few commands the behaviour does not apply to. Confirming the argument with echo confirms nothing about what gh will receive.
The mechanism
Git Bash runs on MSYS2, which bridges a POSIX world and a Windows one. When it starts a program, it rewrites arguments that look like POSIX paths into Windows paths, so that cat /etc/hosts can work at all.
The rewrite is applied only when the program being started is not linked against the MSYS runtime. An MSYS-linked program understands POSIX paths on its own, so its arguments are left alone. A native Windows program does not, so MSYS translates for it.
That single rule explains the whole contradiction. Compare the two binaries:
$ ldd /usr/bin/echo | grep msys
msys-intl-8.dll => /usr/bin/msys-intl-8.dll
msys-2.0.dll => /usr/bin/msys-2.0.dll
msys-iconv-2.dll => /usr/bin/msys-iconv-2.dll
$ where gh
C:\Program Files\GitHub CLI\gh.exe
$ ldd "/c/Program Files/GitHub CLI/gh.exe" | grep -c msys
0
echo links msys-2.0.dll, so it keeps /user/repos. gh.exe links nothing from MSYS, so it gets C:/Program Files/Git/user.
And C:/Program Files/Git is not arbitrary: it is the Git for Windows install root, which MSYS treats as the POSIX filesystem root. /user is being resolved against it exactly as /etc or /usr would be.
What it affects
Any native Windows executable invoked from Git Bash with an argument beginning with a single slash. Three measured on the same machine:
| you type | what happens |
|---|---|
gh api /user | error naming C:/Program Files/Git/user |
cmd //c echo /user | prints "C:/Program Files/Git/user" |
openssl ... -subj /CN=test | silent failure, no certificate, no error |
The openssl case is the one to be afraid of. It is a native binary — ldd reports zero MSYS libraries — and with a converted subject it simply produces nothing and says nothing:
$ openssl req -x509 -nodes -newkey rsa:2048 -keyout k.pem -out c.pem \
-days 1 -subj /CN=test
$ openssl x509 -in c.pem -noout -subject
<- no output: no certificate
$ openssl req -x509 -nodes -newkey rsa:2048 -keyout k.pem -out c.pem \
-days 1 -subj //CN=test
$ openssl x509 -in c.pem -noout -subject
subject=CN=test
No diagnostic, no non-zero message on screen, no certificate. The same command with one extra slash works.
Docker volume mounts and Kubernetes resource paths are commonly reported to hit the same rule, but those tools were not installed on the machine used here, so they are not claimed as measured.
A full URL is safe, because https://host/user does not begin with a slash — only the bare path form is affected:
$ curl -o /dev/null -w "%{url_effective}" https://httpbin.org/anything/user
https://httpbin.org/anything/user
Three fixes, all verified
Omit the leading slash
The simplest, and what the CLI itself suggests. Only works for tools that accept a relative form.
$ gh api user --jq .login
marche11
MSYS_NO_PATHCONV=1
Disables conversion for one command. Use this when the leading slash is required and cannot be dropped.
$ MSYS_NO_PATHCONV=1 gh api /user --jq .login
marche11
Set it for a whole script with export MSYS_NO_PATHCONV=1, but do so deliberately: anything in that script that *does* need a real path translated will then break instead.
A double leading slash
MSYS treats // as an escape and strips one slash without converting. It is the terse fix, and it survives being pasted into a Makefile or a CI step where setting an environment variable is awkward.
$ gh api //user --jq .login
marche11
All three return the same correct answer. The surrounding environment for these runs was MSYSTEM=MINGW64 with MSYS_NO_PATHCONV unset.
Why this one is worth knowing
The failure has three properties that together make it expensive:
- It happens before your program runs. No amount of reading your own code
will find it, because your code is correct.
- The obvious check exonerates the shell.
echois MSYS-linked, so it
reports that nothing is wrong.
- It usually does not say so.
ghis the exception. Most tools report a
confusing downstream error — a 404, a missing file, an invalid resource — and you go looking at the wrong layer.
The general form: when a program receives something you did not type, check whether anything between you and it is allowed to rewrite arguments. On Git Bash, something is.
Measured on
Windows 11, MSYSTEM=MINGW64 (Git for Windows), MSYS_NO_PATHCONV unset, GitHub CLI at C:\Program Files\GitHub CLI\gh.exe, OpenSSL from the Git for Windows distribution. Every command block above is real output from that machine. Claims about tools that were not installed are marked as unmeasured.