Skip to content

Instantly share code, notes, and snippets.

@dlbewley
Last active August 20, 2021 00:57
Show Gist options
  • Save dlbewley/90fa9c31d5847633c2186eb2b35715a1 to your computer and use it in GitHub Desktop.
Save dlbewley/90fa9c31d5847633c2186eb2b35715a1 to your computer and use it in GitHub Desktop.
Git pre-commit hook to allow tracking of example secrets but deny changes.
#!/bin/sh
# once you have tracked a file, .gitignore will not have an effect on it, even if you
# ignore the enclosing directory.
# be sure to commit example secrets before adding this to .git/hooks/pre-commit
# Redirect output to stderr.
exec 1>&2
DENY_LIST="secrets|certs"
if test $(git diff --cached --name-only | grep -E "$DENY_LIST" | wc -l) != 0; then
echo "Error: Do not attempt to commit modified example secrets or add any more."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment