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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners