Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created September 6, 2013 15:46
Show Gist options
  • Save sindresorhus/6465739 to your computer and use it in GitHub Desktop.
Save sindresorhus/6465739 to your computer and use it in GitHub Desktop.
Git hook to install npm dependencies after a `git pull`. Run `chmod +x post-merge` and put it in `.git/hooks/`. Though could really do whatever.
#!/bin/sh
npm install
@simonhaenisch
Copy link

simonhaenisch commented Dec 23, 2017

@pajtai see nvm-sh/nvm#688 (comment) (googled for "git hook nvm path")... don't be so lazy and do some research 🤓 your problem is not related to this script.

@robrecord
Copy link

robrecord commented Jul 6, 2019

#!/usr/bin/env bash

set -e

prevHEAD=$1
newHEAD=$2
checkoutType=$3

[[ $checkoutType == 1 ]] && checkoutType='branch' ||
checkoutType='file' ;

check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
}

[[ $checkoutType = 'branch' ]] && {
    
    changed_files="$(git diff-tree -r --name-only --no-commit-id $prevHEAD $newHEAD)"
    
    # node - use whichever works for you
    check_run yarn.lock "yarn install"
    # check_run package-lock.json "npm install"

   # composer
    check_run composer.lock "composer install"
}

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