Skip to content

Instantly share code, notes, and snippets.

@arturadib
Last active December 21, 2023 08:54
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arturadib/97a17752301ee796f9a0 to your computer and use it in GitHub Desktop.
Save arturadib/97a17752301ee796f9a0 to your computer and use it in GitHub Desktop.
Pre-commit hook to prevent debug code from being committed
#
# Paste this script in your .git/hooks/pre-commit file (create one if it doesn't exist yet)
# To prevent debug code from being accidentally committed, simply add a comment near your
# debug code containing the keyword !nocommit and this script will abort the commit.
#
if git commit -v --dry-run | grep '!nocommit' >/dev/null 2>&1
then
echo "Trying to commit non-committable code."
echo "Remove the !nocommit string and try again."
exit 1
else
exit 0
fi
@Pochwar
Copy link

Pochwar commented Aug 9, 2017

Very usefull, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment