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

How to prevent merging of one branch to another

bbopanna January 30, 2017

Is there a way to prevent merging of one branch to another. We have branches like 15-maint 16-maint master, we merge forward from 15-maint to 16-maint and also from 16-maint to master but never from 16-maint to 15-maint or from master to 16-maint. Sometimes due to human error, of the person merging, higher branch is merged to lower - like 16-maint to 15-maint or master to 16-maint. Is there any way to prevent this by means of hooks or configs in Bitbucket ?

1 answer

1 vote
Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 30, 2017

Hi Bopanna

You can use branch level permissions and a branch naming convention to limit who has the capability to merge. Take a look at the documentation available at https://confluence.atlassian.com/display/BitbucketServer/Using+branch+permissions

Cheers

Bhushan

bbopanna January 30, 2017

@Bhushan Nagaraj : Thankyou for the documentation link. But It does not provide the option to achieve what I am asking...

Like Charlie DeVoe likes this
Ulrich Kuhnhardt [IzymesDev]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2017

@b bopanna would you please elaborate why branch permissions won't work for you? 

bbopanna January 31, 2017

@Ulrich Kuhnhardt [Izymes]: There are 4 restrictions available :

i. Prevent all changes

ii. Prevent deletion

iii. Prevent rewriting history

iv. Prevent changes without a pull request

Now how can I use these to configure my lower branches to not allow merges from higher ? (do not permit merge of master to 16-maint while allowing merging of 15-maint to 16-maint ?)

Like # people like this
Faris Abdulla February 21, 2019

I'm looking for the solution similar to the issue posted here. How can I restrict committers from merging `any branch` -> `master` except `develop` branch.

Use cases:

* prevent from merging feature/bugfix/.. branches to master

* except develop to master

 

Can anyone help to achieve this using bitbucket.

Like # people like this
TVeal June 14, 2019

@Bhushan Nagaraj as others have commented, this does not answer/fulfill the the OP's question. There's a valid use case to set branch merge checks such as: "Only let qa branch merge into prod branch". Or "Only let branch pattern x merge into target y branch."

This should be a setting/feature of Bitbucket. You can't accomplish this easily or cleanly with user/group/access key permissions on branches. Arguing that you use a set of required reviewers for this check is hacky and introduces human error and bottle necks.

Like # people like this
Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 16, 2019

@TVeal definitely not trying to argue, only trying to help :)

The natively supported features for branch permissions and merging is documented in the link I have provided previously.

For more complex use cases and scenarios, you can write a custom hook at the various trigger points available. This is documented at https://developer.atlassian.com/server/bitbucket/how-tos/hooks-merge-checks-guide/

For the examples you have provided, you could use the PULL_REQUEST_MERGE trigger.

Hope that helps.

Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2019

Hello All!

Just to offer a suggestion of what we have done in this same scenario.  We have a small group (in our case 3) Git experts who are added as default reviewers and only they are capable of merging into the master branch or the 16-maint equivilant.

We are using the Prevent all changes with an exception to the single group that has our git experts on it so they are notified when changes come in for that branch and they are the only ones who can merge to it to ensure we don't have accidents.

Now, it's true these are still humans who can make mistakes but since it is a smaller group who are on the same team and they are experts we have significantly fewer issues doing it this way.

Just another thought.

-James

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events