Install required packages
Install the packages that you'll need. Drupal/coder includes phpcs. If you're not wanting to use a specific hook, then you don't need to install the associated packages.
composer global require drupal/coder phpmd/phpmd sebastian/phpcpd
Set the path in your shell startup script (ex: .zshrc or .bashrc).
Set Drupal code sniffer.
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
Set Drupal as the default sniffer (optional).
phpcs --config-set default_standard Drupal
Copy all files in this gist
Set up the git template directory.
git config --global init.templatedir '~/.git-templates'` mkdir -p ~/.git-templates/hooks
Remove any files now that you don't want to use. Perhaps you want to remove the prepare-commit hooks, or just remove one or two pre-commit hooks. Unless you are getting rid of all pre-commit hooks, you want to keep the
Copy all files into ~/.git-templates/hooks.
Make sure all of the scripts are executable.
chmod a+x ~/.git-templates/hooks/*
You may want to modify phpmd-ruleset.xml. This file is intended as a starting point, but there are many rules that you may or may not want included. Configure it to your liking.
Every pre-commit hook has the ability to prevent a commit from happening when errors are encountered. For several of them, I commented out the code that would prevent the commit. If you want to be more strict, then uncomment those lines.
Most of the commit hooks have arrays defined for file extensions to include, file patterns to ignore, and directories to ignore. Modify these as appropriate for your own projects. These are configured for common Drupal 7/8 patterns.
Copy git hooks into specific repositories
Any new repository inited will get all of the hooks in the templates dir.
For existing repos, running
git init will copy in the hooks as well, but it won't override hooks that already exist in the local repo. To override hooks that already exist, you need to delete the hook, then run
git init. You could also use this script that deletes existing hooks for you, then runs
git init: https://gist.github.com/bdlangton/a03686bbe0387f5b2539350bd3a3c453