Last active
June 18, 2024 04:54
-
-
Save dathanb/f37a820776d97585ccce811a35c15197 to your computer and use it in GitHub Desktop.
Git pre-commit hook to stop commit if changes contain sensitive values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# pre-commit hook to prevent a commit if the commit includes changes that | |
# match a set of stop strings | |
FORBIDDEN='DO NOT COMMIT' | |
git diff --cached | grep -q -E "${FORBIDDEN}" | |
ret=$? | |
if [[ $ret = 0 ]]; then | |
echo "COMMIT REJECTED\nFound changes containing forbidden \"${FORBIDDEN}\" references. Please remove them before committing" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment