{"thread":{"id":"65616","subject":"git hard-codes use of /bin/sh for aliases","startedAt":"2026-05-11T21:21:42Z","lastAt":"2026-05-11T22:46:08Z","messageCount":3,"participants":["Thorsten Glaser","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"543094","messageId":"6791cb26-16af-dcda-1dae-82b85da6fb0f@b1-systems.de","threadId":"65616","inReplyTo":null,"subject":"git hard-codes use of /bin/sh for aliases","fromName":"Thorsten Glaser","fromEmail":"tglaser@b1-systems.de","sentAt":"2026-05-11T21:13:18Z","receivedAt":"2026-05-11T21:21:42Z","isPatch":false,"body":"Hi,\n\ngit aliases don’t use the user’s shell but a hardcoded /bin/sh,\nand this cannot be made configurable.\n\nThis, unfortunately, breaks quite some aliases and they cannot\nbe made portable by adding something like core.sh = /bin/mksh\nto the .gitconfig.\n\nI’d love if this could be made configurable.\n\nbye,\n//Thorsten\n-- \nThorsten Glaser\nLinux / Unix Developer\nTel.: +49 160 91168501\nE-Mail: tglaser@b1-systems.de\n\nB1 Systems GmbH\nOsterfeldstraße 7 / 85088 Vohburg / https://www.b1-systems.de/\nGF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt, HRB 3537\n"},{"id":"543096","messageId":"agJaS0xuMaLm6UZv@fruit.crustytoothpaste.net","threadId":"65616","inReplyTo":"6791cb26-16af-dcda-1dae-82b85da6fb0f@b1-systems.de","subject":"Re: git hard-codes use of /bin/sh for aliases","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-05-11T22:38:03Z","receivedAt":"2026-05-11T22:38:10Z","isPatch":false,"body":"On 2026-05-11 at 21:13:18, Thorsten Glaser wrote:\n> Hi,\n> \n> git aliases don’t use the user’s shell but a hardcoded /bin/sh,\n> and this cannot be made configurable.\n> \n> This, unfortunately, breaks quite some aliases and they cannot\n> be made portable by adding something like core.sh = /bin/mksh\n> to the .gitconfig.\n> \n> I’d love if this could be made configurable.\n\nYes, I believe they use `/bin/sh`, except on Windows, where they may\nlook up things in the PATH.  It is very much intentional that they use\nsh because it means that aliases work in a consistent way across\nplatforms and that they work at all.\n\nOn Linux, I have mksh, but my work machine on macOS does not, so\nspecifying `core.sh = /bin/mksh` would not work on all my systems.  If\nyou have system-level aliases as well as user-level aliases, then you\nneed to pick a particular shell and letting the user choose will likely\nbreak the system-level aliases.  This is not a hypothetical: my last\ncompany shipped system-level aliases on development VMs while users were\nfree to customize their user-level aliases (and shell).\n\nThis will absolutely be a problem on Windows, where you have CMD,\nmultiple versions of PowerShell, and bash, all with different syntax.\nSome versions of PowerShell also corrupt non-Unicode data sent through\npipelines as well, which means they're effectively useless for\ngeneral-purpose scripting.\n\nIt can also lead to odd behaviour on some shells because, for instance,\nzsh runs a config file with `-c`, `.zshenv`, that can make the shell\nvery much less POSIX compliant, so behaviour can differ substantially\nfrom sh.\n\nI'll also note that Git doesn't handle aliases specially.  Git has a\nwith-shell and a without-shell mode for running commands, and we use the\nformer for aliases.  We definitely do not want the with-shell mode to\ngenerically allow arbitrary shells because we cannot handle non-POSIX\nshells and will not quote correctly for them (almost certainly leading\nto security vulnerabilities).  We also format the shell command as \"%s\n\\\"$@\\\"\", which also basically requires a POSIX shell to work, and we\ndon't want to work around people's use of non-POSIX shells; that way\nmadness lies.\n\nHowever, because mksh is POSIXy, you could build Git on your system with\n`SHELL_PATH=/bin/mksh`, which would use `/bin/mksh` everywhere that the\nshell is invoked.  That feature exists primarily for systems where `sh`\nis not POSIXy or doesn't support `local` (which I know mksh does), but\nthere's no reason you can't use it yourself.\n\nThere has been some discussion about this issue in the past (in the\ncontext of PowerShell) at\nhttps://lore.kernel.org/git/CAAXzdLXt4+-34+OhS=Jn=-VeORN3Y2jMzzg9+bhyn88aN4hm0A@mail.gmail.com/ .\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"543097","messageId":"9f279637-c0fe-c88b-24de-3a00b957ae3b@b1-systems.de","threadId":"65616","inReplyTo":"agJaS0xuMaLm6UZv@fruit.crustytoothpaste.net","subject":"Re: git hard-codes use of /bin/sh for aliases","fromName":"Thorsten Glaser","fromEmail":"tglaser@b1-systems.de","sentAt":"2026-05-11T22:46:04Z","receivedAt":"2026-05-11T22:46:08Z","isPatch":false,"body":"On Mon, 11 May 2026, brian m. carlson wrote:\n\n>On Linux, I have mksh, but my work machine on macOS does not, so\n>specifying `core.sh = /bin/mksh` would not work on all my systems.  If\n\nBut it could be made possible by pointing it to ~/.etc/bin/mksh\non the Macintosh…\n\n>I'll also note that Git doesn't handle aliases specially.  Git has a\n>with-shell and a without-shell mode for running commands, and we use the\n>former for aliases.\n\nAh, okay.\n\nI was merely wondering that it was not configurable for aliases.\n\nWhen looking at the aliases in detail, I found that I already invoked\nmksh -c '…' in those that used mksh-specific code, and that the one\nthat failed merely uses a recent POSIX sh construct that /bin/sh on\na customer system does not yet implement and I could reword it.\n\nbye,\n//Thorsten\n-- \nThorsten Glaser\nLinux / Unix Developer\nTel.: +49 160 91168501\nE-Mail: tglaser@b1-systems.de\n\nB1 Systems GmbH\nOsterfeldstraße 7 / 85088 Vohburg / https://www.b1-systems.de/\nGF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt, HRB 3537\n"}]}