no-commit pre-commit

Copy to .git/hooks/pre-commit:

#!/bin/sh

if git rev-parse --verify HEAD >/dev/null 2>&1; then  
  against=HEAD
else  
  # Initial commit: diff against an empty tree object
  against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

exec 1>&2

for FILE in `git diff-index --cached --name-status $against -- | cut -c3-`; do  
  if grep -q 'NOCOMMIT' "$FILE"; then
    echo $FILE 'contains NOCOMMIT!'
    exit 1
  fi
done

exit 0  

The hook will prevent any file containing the text NOCOMMIT from being committed.

How to enable a global pre-commit hook.