How to block pushes to a branch in Bitbucket
A step by step guide on creating branch restrictions that deny pushes to specific branches in Bitbucket.
If you are looking to block commits to a local branch, we recommend that you follow the tutorial below.
Step One: Go to the Repository Settings
In Bitbucket, navigate to the repository and select Repository Settings.
Step Two: Select Branch Restrictions
On the left menu side bar, select Branch Restrictions.
Step Three: Add a Branch Restriction
Click Add a Branch Restriction.
Please note that if branches are present this button will appear on the top right as shown below.
Step Four: Fill in the details
Fill in the details for the branch restriction that you wish to create and click Save.
The branch will now appear in the Branch Restriction page as shown below.
Step Five: Test
In Terminal or Sourcetree, try to push an innocent commit to your repo and confirm that it is denied.
Looking to prevent commits to a local branch ?
To prevent commits to specific local branches, you must use a pre commit githook script.
Read the article linked below to learn about the code that you must use.