Keeping Pry Breakpoints out of Git

Last Updated: Apr 19, 2016

My Ruby workflow as of late has almost always contained Git for version control, and Pry for debugging.

Although it’s extremely convenient during development to add a quick breakpoint using binding.pry, it can be a bit frustrating to clients if you accidentally deploy with these breakpoints still intact.

After hunting around for a bit, I decided to write a pre-commit hook that would check the files I was about to check in to ensure that I didn’t accidentally still have breakpoints enabled.

# Git pre-commit hook to check all staged Ruby (*.rb/haml/coffee) files

for Pry binding references




ln -s /path/to/ /path/to/project/.git/hooks/pre-commit


Based on


# FILES_PATTERN='.(rb|haml|coffee)(..+)?$' FORBIDDEN='binding.pry'

git diff –cached –name-only | \ grep -E $FILES_PATTERN | \ GREP_COLOR='4;5;37;41' xargs grep –color –with-filename -n $FORBIDDEN && \ echo 'COMMIT REJECTED' && \ exit 1

exit 0

This file just needs to be saved to /path/to/source/.git/hooks/pre-commit and made executable.

curl $HOOK_URL > /path/to/source/.git/hooks/pre-commit
chmod +x /path/to/source/.git/hooks/pre-commit

If you happen to leave a breakpoint intact, the next time you try to commit your changes, the commit will fail and indicate where these breakpoints are, and what files need to be updated to allow the commit to succeed.