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

How can I block merges in local?

Pablo Hernando Izquierdo August 31, 2023

Hello,

Is it possible to configure a repository so its not possible to merge in local, leaving as the only option merging by BB pull requests, where I can impose merge-checks?

Many Thanks.

1 answer

2 votes
Saxea _Flowie_
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.
August 31, 2023

Hi @Pablo Hernando Izquierdo

You can't prevent local merges through Bitbucket configurations, but you could implement a Git hook to discourage any local merging. However, it's worth noting that Git hooks can be easily bypassed, so they serve more as a guideline than as a strict rule. That said, you can use Bitbucket's branch permissions to protect remote branches by disabling direct merges or writes. This allows merges to occur only via pull requests. By protecting the remote branch in this manner, you ensure that even if someone bypasses the local Git hook, Bitbucket will reject the push.

Pablo Hernando Izquierdo September 4, 2023

Hello,

Thanks for your answer.

To make sure I understand what you say. The configuration wold block any push to the remote if you made a local merge, but if it does not have a local merge you could push to the remote?

In that case, wich would be the configuration for setting this up?

Thanks.

Pablo.

Saxea _Flowie_
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.
September 4, 2023

The idea is that using Bitbucket's branch permissions, you can protect certain branches, usually the remote origin/main branch. So locally, you clone the repo, branch from 'main' with a new branch named 'feature-A' and then push your 'feature-A' to remote and create a pull request to merge 'origin/feature-A into 'origin/main´. 

By protecting the remote using Bitbucket branch permission users would still be able to clone your repo, checkout main and make a commit to local main. However it would block when trying to push to remote 'origin/main.

Now, if you want to, you could also have a git hook locally that would prevent someone from commiting to main locally. It would be more a way to catch it early and guide the user to use a branching and create a PR. It might not be worth the hassle of setting up hooks, if you only doing for this reason. As I already mentioned it is easy to bypass maliciously or because of a misconfiguration in the hooks. So you need to rely on the remote branch protection to effectively enforce this. 

Hope this helps clarify it.

Pablo Hernando Izquierdo September 4, 2023

Hello,

Okey, I understand what you mean, but what i need, is to block merging in local to enforce the mergechecks I have on PRs.

So the developers can clone a repo and make changes in development, and in release, pushing them to the remote, but if they tried to merge development in release in local and then push it, block that push. So if they want to merge, they have to create a PR.

Is that possible?

Many thanks.

Pablo.

Saxea _Flowie_
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.
September 4, 2023

Yes, that's possible - just use Bitbucket's branch permissions. In this case you would protect 'release' and allow write only via PRs.

Like Sabine Mayer likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events