Better safe than sorry: use git hooks to avoid mistakes

Nicolás Galdámez
Unagi
Published in
2 min readFeb 14, 2022
Illustration by Semenin Egor from Ouch!

Debugging our applications is a task that is part of our daily routine. To be honest, it is not something I love doing, but I think I´ve learned how to live with it without suffering.

Michael knows

Fortunately, to make debugging more enjoyable, there are many tools. Two of my favorites are binding.pry (Ruby) and debugger (js).
Both tools allow us to set up breakpoints in our code, in order to read variables and execute commands when the execution of our application reaches each breakpoint.

I use both tools a lot and can’t really imagine developing without them. The problem is that sometimes I end up finding out that I forgot to remove a binding.pry or debugger after I created the Pull Request.

Since it didn’t happen to me once, I now have a hook in git that checks if I left any debugging instructions before committing. Now, if I left a binding.pry and tried to commit, the operation fails 💪.

To include this hook, all I had to do was create a pre-commit script and include it in the my_repo/.git/hooks directory. The script is very simple:

If you try to commit you´ll receive the error on your terminal:

Do you use hooks in your projects? I would love to hear about your experience.

If you liked this article, you may be interested in one of these:

--

--

Nicolás Galdámez
Unagi
Editor for

Co-fundador de @unagi. Me gusta el cine, la lectura, y la ensalada de frutas.