Interview Prep/Git & GitHub/GitHub features, history rewriting and scale

How can you build a commit by hand with plumbing commands?

AdvancedConceptGitHub features, history rewriting and scale
Answer

Write blobs, build a tree from the index, create the commit with commit-tree and move the ref with update-ref. This is what git commit does internally and is handy for scripted release commits and bots.

blob=$(echo 'v2' | git hash-object -w --stdin)
git update-index --add --cacheinfo 100644,$blob,VERSION
tree=$(git write-tree)
commit=$(git commit-tree $tree -p HEAD -m "bump version")
git update-ref refs/heads/main $commit
All Git & GitHub questions Roadmap: Git & GitHub

More on GitHub features, history rewriting and scale