Tips
Testing
Laravel
Tips and Tricks

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

by Vladimir Nikolic, CEO Coding Wisely

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.

About the Author:

Vladimir, with over 25 years in the software industry, serves as the CEO of Coding Wisely.

Disclaimer:

The information provided in this article is based on the author's knowledge and experience as of the publication date. Technology and tools may have evolved since then. Always refer to the official documentation for the latest instructions and updates.