Supplying Git a commit message prepared ahead of time

Friday, 28 Mar 2025

Say you want to write script that will set up the next Git commit for you without creating it – just stage some content and prepare a commit message. The next bare git commit should automatically populate the editor with that message, without any flags passed to it, nor any Git configuration changes, and without affecting any subsequent invocations of git commit. The staging part is obvious… but where do you put the commit message?

The answer, which appears to be undocumented, turns out to be .git/SQUASH_MSG:

echo 'there we go' > .git/SQUASH_MSG

If you now run git commit, your editor will open with the “there we go” commit message already entered.