HACKER Q&A
📣 mroche

Git Hooks, who uses them and for what purpose?


https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

Decided to learn more about them the other day as they seem interesting. In a quick search here for past discussions it seems this feature is used in a variety of ways and more-so than I had anticipated. For those of you that use git hooks, how do you implement/enforce their usage for projects, and what are you doing with them?


  👤 alexjm Accepted Answer ✓
A couple years ago, I was designing an XML schema. The document was a mix of the formal schema and English prose explaining each element. I used a pre-commit hook that extracted the RelaxNG schema and confirmed that it was well-formed, which helped me avoid committing invalid versions of the document.

On the server side, I have a post-receive hook in the repo for a website. When I push to 'develop' it runs the static generation script and deploys to my local server as a preview. When I push to 'master' it builds and pushes to production.


👤 smt88
We use them to reformat code before it hits any shared branch, and we also reject commits that fail linting (unless they're going into a hotfix branch).

Formatting all code using the same strict settings is hugely helpful when looking at change history. It also frees developers from ever thinking about formatting, which takes up many more brain cycles than people realize.


👤 auslegung
I use prepare commit hook to enforce a commit template on myself that includes the github link to the issue. We also use them as a team to format code.