Just found this in git help rev-parse
git rev-parse --is-inside-work-tree
prints true if it is in the work tree, false if it’s in the .git tree, and fatal error if it’s neither. Both true and false are printed on stdout with an exit status of 0, the fatal error is printed on stderr with an exit status of 128.