Just Some Git Magic

vlacroix.ca

< back

2021-05-16

This might be trivial to some, but today I set up a special piece of git magic for this website.

The Magic

Using a post-receive git hook, I can have this website update automatically whenever I push a commit to its git repository on this server.

#!/bin/sh

DEPLOY_DIR=/path/to/www/htdocs
REPO_DIR=/path/to/git/repo

git --work-tree=$DEPLOY_DIR --git-dir=$REPO_DIR checkout -f master
make -C $DEPLOY_DIR

Beautiful, isn’t it? With just a few lines of code, I’ve replicated the main function of a product like GitHub Pages.

Remember KISS: Keep it simple, sisters!