You have non-breaking space instead of regular space between your command and its parameters:
$ od -a <<EOF
[user ~]$ git --git-dir="$HOME/.git/" --work-tree="$HOME" status
EOF
0000000 [ u s e r sp ~ ] $ sp g i t B sp -
0000020 - g i t - d i r = " / h o m e /
0000040 k n i t t l / . g i t / " B sp -
0000060 - w o r k - t r e e = " / h o m
0000100 e / k n i t t l " sp s t a t u s
0000120 nl
0000121
That B sp should be only sp.
You can also use xxd to get a hex dump:
$ xxd <<EOF
[user ~]$ git --git-dir="$HOME/.git/" --work-tree="$HOME" status
EOF
00000000: 5b75 7365 7220 7e5d 2420 6769 74c2 a02d [user ~]$ git..-
00000010: 2d67 6974 2d64 6972 3d22 2f68 6f6d 652f -git-dir="/home/
00000020: 6b6e 6974 746c 2f2e 6769 742f 22c2 a02d knittl/.git/"..-
00000030: 2d77 6f72 6b2d 7472 6565 3d22 2f68 6f6d -work-tree="/hom
00000040: 652f 6b6e 6974 746c 2220 7374 6174 7573 e/knittl" status
00000050: 0a
As you can see, there are two bytes between the command and its arguments: c2 a0 (non-breaking space), but it should be 20 (space).
Your command must be:
[user ~]$ git --git-dir="$HOME/.git/" --work-tree="$HOME" status
but you have:
[user ~]$ git --git-dir="$HOME/.git/" --work-tree="$HOME" status
Can you spot the difference? :)
gitand its parameters?[~]$ echo $HOME /home/useras expected. As you might notice it actually expands fine in the error message in the post.git --git-dir="$HOME/.git/" --work-tree="$HOME" statusIMO could be simplygit -C "$HOME" status