I have a git repo in /foo/bar/baz with a large commit history and multiple branches.
I now want /foo/qux to be in the same repo as /f
1 addition to the accepted answer, which helped me get it to work: when I put the listed text in a shell script, for some reason the -e was kept. (quite likely because I am too thick to work with shell scripts)
when I removed the -e , and moved the quotes to encompass everything, it worked.
SUBTREE2=echo "040000 tree $SUBTREE1 modules" | git mktree
note that there is a tab between $SUBTREE1 and modules , which is the same \t that -e should interpret.