Skip to content

Instantly share code, notes, and snippets.

@jlabs
Last active November 18, 2025 12:03
Show Gist options
  • Select an option

  • Save jlabs/6989c9b0de088cea5e3e4380ab3d4cb2 to your computer and use it in GitHub Desktop.

Select an option

Save jlabs/6989c9b0de088cea5e3e4380ab3d4cb2 to your computer and use it in GitHub Desktop.
Git hook for DDEV + Craft CMS changes on git pull
#!/bin/bash
# Get changed files in the last merge
changed_files=$(git diff-tree -r --name-only ORIG_HEAD HEAD)
# If package.json or package-lock.json changed, run npm install
if echo "$changed_files" | grep -q 'package.json'; then
npm i
fi
# If composer.json changed, run composer install
if echo "$changed_files" | grep -q 'composer.json'; then
composer install
fi
# Always run these commands
php craft up
npm run build
php craft clear-caches/all
@jlabs
Copy link
Author

jlabs commented Jan 20, 2025

Copy to .git/hooks/ as post-merge file. It then runs whenever commits are pulled and checks for changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment