brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: commit.template pre-fills your commit message

Commit
~/tips/tip-git-commit-template

cat ~/tips/tip-git-commit-template.md

Starts every commit message editor with a text of your own, such as a checklist.

If a project has a message format or a checklist you keep forgetting, put it in the editor where it cannot be missed. Git can start every commit message from a file you choose.

Create a file, for example ~/.gitmessage:



# Summary in 50 characters or less (imperative: "Fix", "Add")
#
# Why was this change needed? What does it affect?
#
# Ticket: 

Then point git at it:

git config --global commit.template ~/.gitmessage

Now git commit without -m opens your editor with that text already in place. Lines that start with # are comments and are dropped from the final message, which is also why the template works as a reminder without ending up in the history.

The setting takes the path of the file, and the manual gives no default, so nothing happens until you set it. Leave out --global to use a template for one repository only, which suits a project with its own format.

Caveats: the template only appears when git opens an editor. git commit -m "..." skips it, and so do merges and rebases that write their own messages. If you save the template unchanged, the message is empty after the comments are stripped and git cancels the commit, which is the behaviour you want.

Further reading: git config, commit.template (Git documentation)

More Commit tips if ! head -n1 "$1" | grep -qE '^[A-Z]'; then git commit -C ORIG_HEAD git commit --fixup=reword:HEAD~1 git config --global commit.cleanup scissors git commit -m "Fix login redirect" -m "The old code sent signed-out users to a 404." All Commit tips (7) All topics

Link