Skip to content

Instantly share code, notes, and snippets.

@arnaduga
Last active February 21, 2024 15:06
Show Gist options
  • Save arnaduga/f006c51e72a322bcff5e7b622d35d3da to your computer and use it in GitHub Desktop.
Save arnaduga/f006c51e72a322bcff5e7b622d35d3da to your computer and use it in GitHub Desktop.
Setting up a commit message check
#!/bin/bash
cat $1 | grep -w "test\\|refactor\\|feat\\|fix\\|docs\\|breaking-change\\|chore\\|build" > /dev/null
if \[ $? -eq 0 \]; then
echo "✔️ Commit message CHECKED: good."
else
echo "❌ !!WARNING!! Commit message MUST start with test,refactor, fix, feat, docs, breaking-change, chore or build"
echo "❌ COMMIT ABORDED !!!"
exit 1
fi
# Back to your hom
$ cd
# Create appropriate folder
$ mkdir ~/.git-templates/hooks
# Create the hook file
$ touch commit-msg
### Here, edit the created file and add the "commit-msg" content (GIST)
# Make the file executable
$ chmod a+x ~/.git-templates/hooks/commit-msg
# Set up you git config
$ git config --global init.templatedir '~/.git-templates'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment