Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Protecting the master branch and merging a pull request using command line

We are using Bitbucket cloud and our master branch is protected to disallow any direct pushes.

  1. Once the pull request is approved, Is there a CLI command that can be used to merge the pull request? This is because we would like to increment the version in the master branch right before the merge operation.

  2. Is there a way to allow only specific branches to merge to the master branch?

Also, we are NOT using bitbucket pipelines.

2 answers

1 vote
Mikael Sandberg Community Leader Aug 27, 2021

Hi @Simran,

Welcome to Atlassian Community!

No, there is no specific Git command that would allow you to bypass the protection that you have set up in Bitbucket. By design Git does not care about permissions. The only way around it would be to allow specific users to merge to your master branch.

And there is nothing in Bitbucket that you can configure to only allow merges from specific branches. You could probably do it with git hooks, but you would have to add those hooks to each client and make sure they are updated whenever you make a change to the hook. 

0 votes

I would like to expand on @Mikael Sandberg 's response. 

1. If you have an existing pull request to master in Bitbucket you can merge it with the following REST API command . Restricting commits to master to be only pull request merges is a good idea. Even if someone merges to master locally - they cannot push the changes to remote (Bitbucket)

2. As far as I know there is no technical option to limit the branches you can merge FROM to master. The best way I can think of is to limit the number of users that can merge to master via branch permissions, and then trust those users to adhere to the merge policy.

Let me know if I can help in any other way.

Kind regards, Ulrich


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,170 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you