Discussion of the Benefits and Drawbacks of the Git Pre-Commit Hook
Posted3 months agoActive3 months ago
yeldirium.deTechstory
calmmixed
Debate
60/100
GitPre-Commit HooksSoftware DevelopmentVersion Control
Key topics
Git
Pre-Commit Hooks
Software Development
Version Control
The article discusses the benefits and drawbacks of using Git pre-commit hooks, sparking a community discussion on their effectiveness and potential drawbacks in various development workflows.
Snapshot generated from the HN discussion
Discussion Activity
Very active discussionFirst comment
11d
Peak period
29
Day 11
Avg / period
10.5
Comment distribution42 data points
Loading chart...
Based on 42 loaded comments
Key moments
- 01Story posted
Oct 9, 2025 at 9:18 AM EDT
3 months ago
Step 01 - 02First comment
Oct 19, 2025 at 11:18 PM EDT
11d after posting
Step 02 - 03Peak activity
29 comments in Day 11
Hottest window of the conversation
Step 03 - 04Latest activity
Oct 23, 2025 at 1:30 AM EDT
3 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45527306Type: storyLast synced: 11/20/2025, 6:56:52 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
For formatting I find that it's clearly preferable to lean on the IDE and apply the source code formatter at each file save, and apply it only to the file you are touching. Type checks should be performed right before running unit tests, for the same reason unit tests are executed.
For type checking, I guess that makes sense if your unit tests are small and quick. At work type checking our entire codebase can take like 10-15 seconds with a cold cache, but running all unit tests takes 20 minutes (and multiple shards in CI). Seems like a no brainer to just run the cheap one more often.
I don't think your argument is grounded on reality. Applying whitespace changes does create merge conflicts, and if you have a hook that is designed to introduce said white changes at each commit of a rebase them you are going to have frequent merge conflicts.
Keep also in mind that minor changes such as renaming a variable can and will introduce line breaks. Thus even with a pristine codebase that was formatted to perfection you will get merge conflicts.
> If any of the commits you are rebasing is e.g. breaking formatting rules, they shouldn't have been committed that way in the first place.
You're letting the world know you have little to no programming experience.
Only if you rebase commits prior to the introduction of the hook. Otherwise that whitespace change should be already there in the old commits.
The hooks can fail my commit all they want, but I don't want them actually changing anything I've done, which definitely implies no reformatting in hooks.
yes, formatters run on every commit. not only during rebase, but also every commit beforehand. if that is done consistently, the formatter does not cause merge conflicts.
merge conflicts during rebases due to variable name changes occur without commit hooks, too.
This is what we have in our hooks:
This entire class of automation is awful and defeats the robustness of the tool itself.
All of these things have terribly unpredictable consequences and tend to fail at the worst moments, such as during a SEV.
You can encode the same rules and discipline in other ways that do not impact the health of the system, the quality of the data, or the ability of engineers to do work.
if you're not running auto-format on file-save, your auto-formatter is slow
if you're not running a code checker with auto-fix on pre-commit, your code checker is slow
if you're not running the test-suite on pre-push your tests are slow
if your tooling is slow you need to pick better tooling or make them fast
you want to keep that loop tight and active
And what about tests that only need to run intermittently, such as broken link checkers?
pre-push can run the faster unittest set, ci will run the integration set
aim to keep pre-push duration under 10s
i tend to run only the fast set of tests, or a subset of the environments matrix, on pre-push — CI can take care of the rest while, i move onto do something else
when working with other the CI status is what matters
Or you care about your formatting and don't want to throw them away.
Personally, I don't like auto-formatters. It's like having someone else cleaning up your room. I have put every byte of whitespace where it belongs, I certainly don't want someone else to mess that up.
Of course tests are slow. If they're fast they're skipping something. You probably want to be skipping something most of the time, because most of the time your change shouldn't cause any side-effects in the system, but you definitely want a thorough test suite to run occasionally. Maybe before merge, maybe before release, maybe on some other schedule.
Each individual change might be fine in isolation but cause excessive memory pressure when accumulated with other changes, for example. Unit tests won't catch everything, integration & functional (hardware in-the-loop) tests are needed. I even sometimes have to run tests in a thermal chamber repeatedly to cover the whole -40-105°C temperature range, since the firmware I work on runs on hardware that allows that range & performance varies with temperature.
that's what ci is for
anyway, if you're doing embedded development and can distinguish between different kinds of testing then my previous post is not meant for you
It's fine if the auto formatting tool hasn't been run. If the pre-commit hook changes my files silently, that is a big no-no for me.
I have had tools break things before and it makes it very hard to work out what happened.
Having it fail to push means I get to choose how to fix up my commits - whether I want a new one for formatting changes etc or to go back and edit a commit for a cleaner public history.
100% agree on hooks being readonly.
Username oddly relevant to context btw.
Waiting for a CI step to tell me something's wrong when I could've found out locally is a waste of time.
Sure, I can hand-run checks locally, but having a way of doing it "automatically" pre-push gives me consistency and saves time.
As long as "don't get merged" includes squashing so that whatever your (non)hooks didn't catch locally don't end up causing failures for rebases/merge conflict resolutions for others (assuming there are repo-level hooks people are expected to be using).
But it requires me to remember to set that up for each repo, and this is a massive pain. I'd like to be able to have a "clone with hooks" option, but I don't think anyone has found a way of making that work well without leaving people in danger when they clone a random repo.
I've only encountered those on the server side.
Edit: `git config --global core.hooksPath D:\GitHooks\` is what I needed!
Note that you can skip hooks by passing the --no-verify flag to subcommands. Comes in handy when they're slow and you know that you've just fixed the wrong formatting that the previous invocation of your pre-commit hook complained about.