Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Simran August 27, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 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
Ulrich Kuhnhardt _IzymesCo_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 29, 2021

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 https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/merge . 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

Izymes

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events