GitHub Squash Merges are a Menace
I love squash merging. I think it’s the simplest way to maintain a legible commit history on main
, a shared dev
branch, etc. It’s easy for most people to follow, and it doesn’t require you to be too Big Brained about git. GitHub even provides a convenient interface for doing this, right in the pull request UI!
But GitHub’s squash merge workflow undermines the biggest benefits of squash merges: clear, simple, atomic commit messages that explain what each commit does.
How many times have you seen a commit like this:
commit ed0c641ce592e9cdaa5008264569df068e4e2ab4
Author: Joe Blubaugh <joe.blubaugh@gmail.com>
Date: Wed Aug 31 13:46:06 2022 +0800
Fix a bug where we never commit a database transaction
* Fix a bug where we never commit a database transaction
* lint
* pull request feedback
* lint AGAIN
If your team squash merges in GitHub, this is the easiest commit message, the one that GitHub automatically fills in for you when generating the squashed commit. What we want is:
commit ed0c641ce592e9cdaa5008264569df068e4e2ab4
Author: Joe Blubaugh <joe.blubaugh@gmail.com>
Date: Wed Aug 31 13:46:06 2022 +0800
Fix a bug where we never commit a database transaction
In db/users.go, the transaction that updates users' subscription level in bulk
is never committed. Users don't get access to the proper subscription content
as a result.
This change fixes the bug by using a `defer` to guarantee that the transaction
is committed if there is no error or rollback.
You can promote this practice at your company person-by-person, one slog at a time, but I’ve not yet found a way to get GitHub to stop filling in terrible commit messages by default.