Tom Hale Tom Hale - 1 year ago 112
Git Question

Shell used by git for aliases starting with '!'

What default shell is used by

when executing an alias starting with

I'm suspecting it's /bin/sh, because I'm getting different behaviour when using
in an alias vs in my shell (which is

+ravi@boxy:~/.dotfiles(master*% u+2)$ grep 'test =' ~/.gitconfig
test = "!f() { read -n1 -p "Works?" r; } ; f "
+ravi@boxy:~/.dotfiles(master*% u+2)$ git test
f() { read -n1 -p Works? r; } ; f : 1: read: Illegal option -n
+ravi@boxy:~/.dotfiles(master*% u+2)[2]$ read -n1 -p "Works?" r; # Try it in current shell (bash)
Works?Y+ravi@boxy:~/.dotfiles(master*% u+2)$ # OK, that worked...
+ravi@boxy:~/.dotfiles(master*% u+2)$ grep 'sh =' ~/.gitconfig
sh = "!f() { exec \"$@\"; }; f"
+ravi@boxy:~/.dotfiles(master*% u+2)$ git sh env | grep SHELL
+ravi@boxy:~/.dotfiles(master*% u+2)$ # WTF??????????
+ravi@boxy:~/.dotfiles(master*% u+2)$ type read
read is a shell builtin
+ravi@boxy:~/.dotfiles(master*% u+2)$ which read
+ravi@boxy:~/.dotfiles(master*% u+2)[1]$ # none, so why is the shell behaving differently?
+ravi@boxy:~/.dotfiles(master*% u+2)[1]$ git sh bash -c read -n1
Hmm, this is ok??
+ravi@boxy:~/.dotfiles(master*% u+2)$ # Yes, that worked.

How can I set which shell is used in processsing aliases beginning with

Answer Source

As described here, you can see more with:

GIT_TRACE=1 git test

The workaround is to create a shell script (whose first line can be a shebang #!/bin/bash) named git-xxx. Then any git xxx call would invoke that script (provided it is in the $PATH).

As the OP Tom Hale adds in the comments, /bin/sh is used:

trace: exec: '/bin/sh' '-c' 'echo Which shell?' 
'echo Which shell?'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download