git hooks - pre-commit

I just learned how to make effective use of the git hook pre-commit. Based on a blog post Tips for using a git pre-commit hook I composed myself a pre-commit snippet that essentially stashes everything not staged for commit, runs arbitrary tests from a file and finally restores the stash. A configured git hook will then be executed by git automatically. See the official git hooks documentation for the details and other hooks.

I came across this while creating a team project and wondered A) how can I share my usual tests before commit and B) how can I automate certain tests and operations before a commit, so I don’t forget about them or even worse execute long-running pipelines that will fail because of simple tests I could’ve run locally.

Any thoughts of your own?

Feel free to raise a discussion with me on Mastodon or drop me an email.