Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which shell used for git '!' aliases?

Tags:

git

What default shell is used by git when executing an alias starting with !?

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

+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
SHELL=/bin/bash
+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 !?

like image 907
Tom Hale Avatar asked Feb 17 '26 19:02

Tom Hale


1 Answers

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?'
like image 64
VonC Avatar answered Feb 20 '26 10:02

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!