Skip to content

Catching Problems Before Commit

I still remember the exact moment I felt like a complete fraud: I had just spent forty minutes debugging a massive error in production, only to realize it was a simple syntax mistake that a basic linter should have caught. I was staring at my screen at 11 PM, fueled by nothing but lukewarm coffee and pure frustration, thinking about how much easier my life would be if my computer just stopped me from being stupid. Most tutorials on how to set up pre commit hooks make it sound like this grand, architectural necessity for enterprise-level engineering teams, but honestly? It’s really just about not wanting to feel like an idiot when you push your code.

I’m not going to give you a lecture on the theoretical benefits of the development lifecycle or some bloated, over-engineered workflow that takes three hours to configure. Instead, I’m going to show you the exact, stripped-back way I do it so you can catch your own mistakes before they become actual problems. We’re going to get these hooks running quickly and efficiently, because you have better things to do with your time than chasing down missing semicolons.

Table of Contents

The Git Hooks Configuration Guide You Actually Need

The Git Hooks Configuration Guide You Actually Need

Look, you could technically go into your `.git/hooks` folder and manually write shell scripts for every single check you want to run, but please don’t. I tried that during my first month of bootcamp and it was a nightmare to manage every time I switched machines. Instead, we’re going to use the pre-commit framework, which is basically the industry standard for a reason. It handles the heavy lifting so you aren’t stuck writing boilerplate code just to make sure you didn’t leave a random `console.log` in your script.

This specific git hooks configuration guide is built around getting the framework installed via pip and then creating a simple `.pre-commit-config.yaml` file in your project root. This file is your new best friend; it tells the system exactly which tools to run—like Prettier for formatting or ESLint for catching those annoying syntax errors—before the commit even happens. By automating code linting this way, you’re basically setting up a tiny, automated gatekeeper that catches your mistakes before they ever reach your teammates or your pull request. It’s much better to have a terminal error tell you you’re wrong than to have a Senior Dev point it out in a code review.

Preventing Bad Commits Before They Break Your Day

Preventing Bad Commits Before They Break Your Day

When I first started transitioning from retail to dev, I thought “quality control” just meant double-checking my work before hitting enter. Then I pushed a commit that broke the entire local build because of a single missing semicolon, and I felt like a total idiot. That’s the thing about preventing bad commits: it’s not about being a perfectionist, it’s about protecting your future self from that specific brand of “why is this broken?” panic. Instead of manually running checks every single time, you should be leaning on workflow automation for developers to catch the stupid stuff before it even leaves your machine.

I eventually realized that automating code linting through a hook is basically like having a senior dev hovering over your shoulder, but way less judgmental. It’s not about adding extra steps to your day; it’s about making sure that when you finally do push your code, you aren’t also pushing a mountain of formatting errors or console logs you forgot to delete. Setting this up means you stop wasting mental energy on syntax and start actually focusing on the logic, which is where the real learning happens.

Small Wins That Save My Sanity

  • Don’t try to automate everything at once. I used to try and add every linter and formatter in one go, and I’d end up stuck in a loop where I couldn’t even commit a single line of code because the hook was failing. Start with one thing—like just checking for trailing whitespace—and build from there.
  • Use Husky if you’re in a JavaScript environment. I spent way too long trying to manually wire up scripts in my `.git/hooks` folder, only to realize that my teammates (and my future self) wouldn’t have those same local settings. Husky makes it actually work for the whole repo.
  • Keep your hooks fast. If your pre-commit hook takes more than five or ten seconds to run, you’re going to start typing `–no-verify` just to get your work done. Once you start bypassing your own rules, the whole system is useless. If a test suite is slow, move it to a pre-push hook instead.
  • Learn to read the error messages, not just the “failed” notification. There was a week where I thought my environment was broken, but it turns out my hook was just catching a tiny syntax error I’d missed. If you don’t understand why the hook is blocking you, you’ll just grow to hate the tool.
  • Treat your hook configuration like actual code. It lives in your repo, it gets versioned, and it can break things. If a new hook is causing a headache for the team, don’t just ignore it—fix the config or roll it back. It’s a tool to help you, not a hurdle to jump over.

The TL;DR for when you're too tired to read the docs

Don’t try to write custom shell scripts for your hooks yet; use Husky. I wasted way too much time trying to be “clever” with manual Git configs when a tool that actually works is what you need.

Start small. If you try to run a massive suite of tests on every single commit, you’re going to end up bypassing the hooks entirely because they’re annoying. Just lint your code first and build up from there.

Think of hooks as a safety net, not a punishment. They aren’t there to judge your messy code, they’re just there to catch the stupid mistakes—like a missing semicolon—before they become a headache for the rest of the team.

The Reality Check

The Reality Check of automated hook configuration.

Look, setting up these hooks isn’t about being a perfectionist or following some arbitrary “best practice” just because a senior dev said so. It’s about building a safety net so you aren’t accidentally pushing a massive pile of linting errors or—god forbid—a hardcoded API key into a repo at 11 PM. We’ve covered how to get the configuration running and how to use them to stop those soul-crushing “fix typo” commits from cluttering your history. Once you have this automated, you stop fighting the terminal and start actually focusing on the logic that matters.

If you’re feeling a bit overwhelmed by the setup, just remember that I spent my first three months in a bootcamp basically guessing my way through the command line. You don’t need to master every single Git configuration overnight to be a “real” developer. Just get these hooks working, let them catch your silly mistakes, and give yourself some breathing room to actually learn. You’re doing the work, and honestly, that’s the hardest part. Now go grab some caffeine and get back to building something cool.

Frequently Asked Questions

Do I have to manually set these up every single time I clone a new repo, or is there a way to make it stick?

Ugh, the thought of doing that manually every single time is enough to make me want to quit coding entirely. Honestly, don’t do it. If you’re cloning repos constantly, you need `pre-commit`. It’s a framework that lets you manage your hooks through a simple config file. You just run one install command, and it handles the heavy lifting across your projects. It makes everything “just work” without you having to babysit your `.git/hooks` folder.

What happens if I’m in a massive rush and just need to bypass the hook to push a quick fix?

Look, I’ve been there. It’s 4:45 PM, your coffee is cold, and you just need this one tiny fix to go live. If you’re absolutely desperate, just add `–no-verify` to your commit command. It’s the “emergency exit” that tells Git to ignore the hooks entirely. But seriously? Use it as a last resort. I’ve learned the hard way that bypassing the checks usually just means you’re pushing a headache for your future self.

Won't these hooks make my git commits feel super slow if I'm running heavy linting every time?

Honestly, I had the exact same fear. I didn’t want to spend ten minutes staring at a spinning terminal every time I finished a function. The trick is being selective. Don’t run your entire test suite on every commit—that’s overkill. Stick to lightweight stuff like Prettier or basic linting. If a check takes more than a few seconds, it’s probably better suited for your CI/CD pipeline rather than your local workflow.

Is it better to use a tool like Husky or should I just stick to the raw shell scripts in the .git folder?

Look, I spent way too much time trying to manually tinker with the `.git/hooks` folder when I first started, and honestly? It’s a headache you don’t need. If you’re working on anything more than a solo side project, just use Husky. It keeps everything in your repo so your teammates actually use the same rules. Raw shell scripts feel “purist,” but life is too short to debug why your hooks aren’t running on a colleague’s machine.

About Marisol Ebanks

I am close enough to the start to remember which bit was actually confusing.