🔀 Git: Fix an Alias Expanding Differently Inside a CI Runner
A git alias defined with a ! shell-out prefix runs through whatever shell git invokes it with, and that shell can differ between a developer’s machine and a CI runner’s minimal container image — bash-specific syntax that works fine locally can behave differently, or fail outright, under whatever /bin/sh happens to be symlinked to on that particular runner, making the exact same alias command produce different output in CI than it does anywhere else.
🔎 The Problem
[alias]
lastlog = "!h=$(git log -1 --format=%H); echo ${h:0:8}"
Local machine (bash): prints an 8-character short hash, as intended
CI runner (dash as /bin/sh): "bad substitution" error - ${h:0:8} is a
bash-ism dash doesn't support, pipeline step fails with no clear reason
✅ Fix: Pin the Interpreter, Don’t Assume It Matches Your Shell
- Avoid bash-specific syntax inside a
!-prefixed alias if it also needs to run unmodified in CI — check what shell the runner actually invokes it through rather than assuming it matches your local default. - Pin the alias to an explicit interpreter inside the alias body (
!bash -c '...') rather than depending on whatever/bin/shhappens to be symlinked to on that runner image. - Test the exact alias command inside the same container image CI uses, not just a local terminal, since a shell or locale difference between environments is a common silent cause of an alias “working everywhere except CI.”
🚨 Why This Is Dangerous
- A CI pipeline step that depends on a git alias behaving identically to local can fail outright, or worse, silently produce different output that downstream automation consumes without anyone noticing it’s subtly wrong.
A git alias that starts with ! isn’t running your shell — it’s running whatever shell happens to be standing in for /bin/sh wherever it’s called.





