This is a very easy way to check your PHP syntax before each commit. Git will call the script before it runs your commit. If there are syntax errors found, they won't be committed and they will be reported.
It will only check files that have one of the extensions listed in the $extensions array. It's a pretty simple script and comes in handy if you are working locally before you push to a remote for testing.
Things to note:
- You may have to change the
#!/usr/bin/phpto point to your path for PHP - If you don't want to check untracked files, remove the
$untrackedvariable. - Place
pre-commitfile in your.git/hooksfolder andchmod +x .git/hooks/pre-commit