In this Astro Husky Git hooks video, we start by seeing what the Husky tooling is all about.
With that out of the way, we take an existing git repo and add three hooks.
Hooks are just code snippets which we want to run automatically just before a git operation. As an example, we see a
pre-push hook. In that one, we run the
astro check command
error, stop the commit and give you a chance to update. So the hooks help keep your remote repos
clean. In fact, they are fantastic if you are working in a team.
Anyway, you came here to see the short video, so hit play below! You can drop a comment below or reach out for a chat on Element as well as Twitter @mention if you have suggestions for improvements or questions.
- Astro vanilla-extract post,
- Husky docs ,
- Conventional Commits site ,
- Commitizen repo ,
- Element chat: #Rodney matrix chat ,
- Twitter handle: @askRodney .
- Certainly! To get going, install the Husky package with `pnpm add husky` then run `pnpm husky install` to initialize it. You can add all the popular hooks like commit-msg (e.g. with commitlint for conventional commits), pre-push and pre-commit.
- Astro check, inspired by Svelte check lints your Astro files. It will point out if you stray from best practices, On top if you are using TypeScript in your project, it will spot additional errors. Running it before push code to your remote git repo is a fantastic idea as one final check to make sure your code is spotless!
- Husky git hooks work really well with Astro. If you install Husky, you can first add a prettier formatting script to your project package.json file. For example: `"prettier:check": "prettier --check --plugin=prettier-plugin-astro ."`. Then add a Husky pre-commit script, to run just before each commit: `pnpm husky add .husky/pre-commit "pnpm prettier:check"`. In this case, if formatting is not quite right, the commit will fail, giving you a chance to fix it before finally committing a pristine version!
Have you found the post useful? Would you prefer to see posts on another topic instead? Get in touch with ideas for new posts. Also, if you like my writing style, get in touch if I can write some posts for your company site on a consultancy basis. Read on to find ways to get in touch, further below. If you want to support posts similar to this one and can spare a few dollars, euros or pounds, please consider supporting me through Buy me a Coffee.
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter, @[email protected] on Mastodon and also the #rodney Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Astro as well as SEO. Also, subscribe to the newsletter to keep up-to-date with our latest projects.