Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ai7ch/224ccc94f60ea1ca9f3e6161c8b9bc6a to your computer and use it in GitHub Desktop.
Save ai7ch/224ccc94f60ea1ca9f3e6161c8b9bc6a to your computer and use it in GitHub Desktop.
Git post-receive hook deployment using node, npm and PM2
#!/bin/sh
export GIT_WORK_TREE="/var/www/project"
echo "--> Checking out..."
git --work-tree=$GIT_WORK_TREE --git-dir=/var/repos/myrepo.git checkout -f
echo "--> NPM install..."
cd "$GIT_WORK_TREE"
npm install
echo "--> Restart server..."
pm2 restart {appname}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment