Post Receive Hook

I've been using git for years, but somehow never got into using hooks. In order to make updating this website smoother, I'm trying out a very simple hook script which executes on the server after I commit to it. After getting my local ssh configuration updated so that I didn't have to manually log in each time, the next step was figuring out how to commit directly into the server. This was done by adding a "remote" which is an SSH user@address with full path to the repo on the server.

With this additional remote, I now push into the main repo for storage and then to this new remote when I want to update the site.

On the server, the .git/hooks/post-receive script is waiting and will run:

#!/bin/sh
npm start

Because I'm using 11ty, this triggers a rebuild of the static files. But this script could do whatever you need to build your site.

Although this is a very simple solution, it took me a lot of false starts and wrong ideas before I finally landed here.

Notes for future reference:

On the server

On your local