
Ask HN: Git Hooks, who uses them and for what purpose? - mroche
https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Customizing-Git-Git-Hooks<p>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&#x2F;enforce their usage for projects, and what are you doing with them?
======
alexjm
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.

