How to block pushes to a branch in Bitbucket

Oscar de la Hera Gomez
Three flowers that represent Bitbucket, Terminal and Sourcetree side by side. Beneath them sits the text "Deny Pushes to a Branch."

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

A screenshot of Bitbucket showing a respository. Highlighted on the left menu side bar is the "Repository Settings" tab. Click it and move to the next step.

In Bitbucket, navigate to the repository and select Repository Settings.

Step Two: Select Branch Restrictions

A screenshot of Bitbucket showing the menu bar that appears in the Repository Settings. Highlighted is the "Branch Restrictions" tab. Click it and move to the next step.

On the left menu side bar, select Branch Restrictions.

Step Three: Add a Branch Restriction

A screenshot of the Bitbucket Branch Restriction screen. It has no branch restrictions. We have highlighted the "Add Branch Restriction" button that appears on the center.

Click Add a Branch Restriction.

Please note that if branches are present this button will appear on the top right as shown below.

A screenshot of Bitbucket on the Branch Restriction screen. There are three branch restrictions being displayed. The Add Branch Restriction button now appears on the top right of the screen.

Step Four: Fill in the details

A screenshot of the Bitbucket Add Branch Restriction modal that appears when you click Add Branch Restrictions. We have highlighted the area where you input the branch name (in this case "Main"). We have also highlighted the areas where you can restrict pushes and only allow merges from certain groups or individuals. Finally highlighted is the "Save" button on the bottom right which must be clicked once everything looks good to create the branch restriction.

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.

A screenshot of the Branch Restriction screen with the restriction that we detailed in the prior picture showing up on the screen. This confirms that it has been created.

Step Five: Test

A screenshot of SourceTree showing that a push to the branch has been denied.

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.

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.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details