How to prevent commits to a branch using a pre-commit githook script
To prevent commits from being allowed to specific local branches, add the code in this post to a pre-commit script in your projects githooks folder.

Written by Oscar de la Hera Gomez
First published on 06/16/2023 at 11:15
Last Updated on 06/16/2023 at 15:19

To prevent commits from being allowed to specific local branches, add the code in this post to a pre-commit script in your projects githooks folder.
SubscribeCopy the code below into your pre-commit script and replace BRANCH_NAME with the name of your branch (i.e. main or master).
If you want to disallow multiple branches, copy the code multiple times (i.e. one for dev, one for uat, one for main).
Any Questions?
We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work