Skip to content

Instantly share code, notes, and snippets.

Last active June 7, 2023 18:51
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Git hook to call `bower install` and `npm install` automatically.
echo "[post-rewrite hook: $1]"
# by noahgrant & digitaljhelms
# quick script to call "bower install" and "npm install" automatically if
# bower.json or package.json are changed, respectively
# this assumes one top-level file for each
changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )
if [[ "${changedfiles[*]}" =~ "bower.json" ]]; then
echo "bower installing"
bower install && bower update
if [[ "${changedfiles[*]}" =~ "package.json" ]]; then
echo "npm installing"
npm install
Copy link

Triggered if the bower.json or package.json file(s) are modified in changes being incorporated from a remote repository into the current branch (via git pull and thus git merge, or git rebase). This file should be named "post-rewrite", marked executable, and placed in .git/hooks/ within a local Git clone.

Copy link

kontur commented Jul 28, 2014

Nice! Been thinking about writing something like this myself, but alas you shared it - thanks 👍

Copy link

ghost commented Aug 28, 2014

Awesome, thanks for sharing 👍

Copy link

Thanks for sharing!

There is a minor issue: you should change #!/bin/sh to #!/bin/bash, or you'll get a syntax error. Maybe something is not POSIX compliant, and does not work with "basic" shells like dash.

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