Git hooks to the rescue !!!

Huzefa S Biyawarwala
1 min readJun 5, 2022

--

While doing a commit to the repo we often check for holy mistakes such as adding binding.pry, debugger etc in the commit.

Thanks to the pre-commit hook in Git using which we can avoid adding such words beforehand.

Just follow below simple steps:

  1. Go to your repo’s hooks folder using:
cd your_repo_path/.git/hooks

2. Use any editor vim or nano and create a file named pre-commit without any extensions and paste the content of the below link in the same:

https://gist.github.com/huzefahuzu/ace17ed129cce37b45416e52b0ad4e76

3. Now, change file mode to allow execution by git:

chmod +x pre-commit

4. Now whenever you will commit, this hook will be executed, and if the files in your commit contain any of the words like binding.py , debugger etc it will not allow you to commit unless you remove it.

This was easy, isn’t it !!!

Let me know if you have any questions or suggestions on this, will be appreciated !!!

--

--

Huzefa S Biyawarwala
Huzefa S Biyawarwala

Written by Huzefa S Biyawarwala

Ruby On Rails | MongoDB | ReactJS | AWS | Freelance Consultant

No responses yet