git Create Tree from Arbitrary Directory (works in bare repository)
Consider portable shell
Do we really need Bash for this?  If we can manage without local variables and string indexing, then we could use a leaner, more portable shell instead.  Certainly, there's no benefit using the non-standard function keyword - just omit it.
We probably do want local in the recursive function, but it's good to be clear that we've made the choice for a good reason.
Add some error checking options
set -eu -o pipefail

Use more quoting
We don't want $path or $fullpath to be split:
    for fullpath in &quot;$path&quot;/*; do
        f=$(basename &quot;$fullpath&quot;)

There's some more needed later:
            treeData=$(printf '%s\n%s %s %s\t%s' &quot;$treeData&quot; $mode $type $hash &quot;$f&quot;)
        elif [ -d &quot;$path/$f&quot; ]; then
            # recurse
            treeData=$(printf '%s\n%s' &quot;$treeData&quot; &quot;$(createSubtreeRec &quot;$fullpath&quot;)&quot;)

Shellcheck can't know that $hash will always be a single token, so it recommends more quoting than is actually necessary.