Git hooks - yay or nay?

Many people are very for or against Git hooks - scripts that run automatically on events such as pre-commit and pre-push.

Commonly, they are used for running tasks such as altering a commit message or running before committing automated tests and static analysis before pushing a commit.

I'm on the fence.

I've used them and added support for them to Build Configs, but I don't feel strongly about them.

They are awkward to set up (you need to edit the configuration for them to work) and can be easily disabled or bypassed.

Some people think it's the Developer's responsibility to run the tasks before pushing changes or that they'll be run in a CI pipeline, so why would they need to be run locally?

As I write many small commits and push changes regularly, I can find hooks irritating and prefer to use watchers instead with tools like watchexec and entr.

There are also tools like Captain Hook that are built to manage Git hooks. Maybe, I should investigate it more.

What do you think? Are you yay or nay for Git hooks?

- Oliver

P.S. If you're creating a new Drupal module, try my free Drupal module template.

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.