Sometimes when working on a PHP project where there are a lot of branches potentially sitting on incompatible packages, it can be a pain to always remember to manually run composer i or whatever docker alternative or alias one might be using. I tried to modify this stack overflow https://stackoverflow.com/a/20892987/1972509 to see if this could be comfortably automated via git hooks.

Here's the final script: #!/bin/bash set -e prevHEAD=$1 newHEAD=$2 if ["$newHEAD"!= "$prevHEAD"]; then printf "Post-checkout 'composer install' hook active.\n" composer i >/dev/null 2>&1 & fi

You should be able to see a brief peak in the CPU usage in the very least after every checkout: $ git checkout - Switched to branch 'somebranch' Post-checkout 'composer install' hook active.

Post-checkout 'composer install' hook active.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners