Friday, October 24, 2025

Hooked on Git Hooks

A useful feature of git is hooks.  There are two hooks that I find very helpful at my job.  The first is in my local development environment.  We have this simple post-checkout hook:

git rev-parse --abbrev-ref HEAD > www/app/includes/git-branch.cfm

What this does is write the name of the current branch to a ColdFusion file (yes, we still use ColdFusion) that is included on the footer of every page.  So when doing development or testing, we can just glance at the footer of the page to know which branch we are on.

The second is on our staging and production servers.  We have this post-merge hook:

rm -rf .vscode

rm -rf README.md

rm -rf www/app/testing

gitlog=$(git log -1 --pretty=format:"%s")

timestamp=$(date "+%Y/%m/%d %H:%M:%S")

echo "$timestamp  $gitlog" >> git-pulls.log

After we deploy our code using git, this removes unnecessary files and writes a simple log of what was deployed. 

Speaking of code deployments, we keep our process simple for our internal app.  To deploy changes, we simply do a git pull on the master branch.  If we need to back out changes, we have a short bash script for that:

#!/bin/bash

git reset --hard HEAD@{1}

I understand the need for CI/CD pipelines for bigger projects but sometimes the simple solutions are the best.

 
Blogger Templates