LaravelTips and TricksTipsTesting

February 15, 2024

How to use git hooks to run scripts before the committing code to repo

By Vladimir Nikolic

How to use git hooks to run scripts before the committing code to repo

here iw how.

In root, run this:

touch .git/hooks/pre-commit

Then, make it executable:

chmod +x .git/hooks/pre-commit

#!/bin/sh
echo "Running Pint ... "
files=$(git diff --cached --name-only --diff-filter=ACM -- '*.php');
./vendor/bin/pint $files

git add $files

echo "Running Pest ..." ./vendor/bin/pest --parallel --processes=4

and that is all.

Have a Laravel app that needs a rescue, an upgrade, or a move to Laravel Cloud?

Tell us about the codebase and where it runs. We will tell you what we would do first.

Contact Us