Git Hooks Implementation in Laravel: Unit Testing & Prettier Automation

Cerwyn Cahyono
3 min readJun 22, 2021

As a web developer, we’ll be always working with the team. We want to make sure that our codes have the prettier standard and minimalizing bugs pushed into our git repository. As we already know, we can do those implementations using CI/CD to test our app before the deployment happens. But the question is, can we make that automation run locally whenever developers pushed the codes into the git? So we’re sure that every code that is pushed by developers is bug-free and also has prettier standardization.

We can create & implement these git hooks using the Husky library in our projects, where we set up some things to do before (or after) we commit/push our codes into the version control. We can run any commands that are needed before developers commit/push their codes. So in this article, I’ll show you how to create git hooks before we commit/push codes into the git where we’ll reformat our codes using lint-staged and run the tests inside the Laravel project.

Photo by Marvin Meyer on Unsplash

Goal

At the end of this article, we’ll make 2 hooks: pre-commit and pre-push hooks to the version control.

--

--

Cerwyn Cahyono
Cerwyn Cahyono

Written by Cerwyn Cahyono

PHP/Backend Engineer at Undercurrent Capital Pte Ltd — Data Science Enthusiast