This Git pre-commit hook checks for a keyword ("nocheckin" by default) in staged source files and blocks the commit if any matches are found, with the output of file path, line number and match preview.
It's is inspired by Jonathan Blow's nocheckin setup with SVN, as seen on his programming sessions at
Twitch and YouTube.
Additional credit to DustinGadal on the r/Jai subreddit for original implementation.
Tested on Linux (GNOME OS 50), macOS Sequoia and Windows 11 (with Git for Windows) + GitHub Desktop on each.
- Download the file from above (you can click Download ZIP and extract it), or copy its contents.
- Put & rename the file to
<repo>/.git/hooks/pre-commit. If you already have your own pre-commit hook set up, you can also just call the nocheckin file to execute it. - On Unix systems, mark the file as executable by running
chmod +x ./git/hooks/pre-commit.
pre-commit" for Git to recognize and use it as a pre-commit hook.
- If you don't have a global git hooks folder yet, create one (example:
/Users/tester/.git/hooks) - Set this path in your gitconfig:
git config --global core.hooksPath /Users/tester/.git/hooks - Copy and rename the nocheckin file to
pre-commitinside your hooks folder. Alternatively, call the file from an existing pre-commit hook.
CLI:
- Stage files with
git add <file> ... - Attempt making a commit with
git commit ... - Observe the commit failing when at least one of the staged files contains a
nocheckin.
GUI (Github Desktop)
- Mark files for staging.
- Attempt making a commit.
- Observe the commit failing when at least one of the staged files contains a
nocheckin.
Changing the keyword
You can change the keyword that's used for rejecting commits by setting the NOCHECKIN_KEYWORD environment variable, or editing the default at the top of the script (NOCHECKIN_KEYWORD:-nocheckin)

