Resolving pull requests with merge conflicts when using branch permissions in Bitbucket Server

3bh picture 3bh · Sep 29, 2016 · Viewed 26.4k times · Source

We've started using Bitbucket Server on our team, and want to enforce the use of pull requests to get commits from feature branches into our main integration branches. To enforce this, we turned on the branch permissions feature that prevents merges without a pull request for those branches. This works great, until we get a pull request that has a conflict.

In this case, the instructions say to manually fetch the head of the source branch and merge it to the target, then push this up. However, the merge commit gets rejected by the branch permissions!

Are we missing something here, or is it not possible to manually merge when using branch permissions?

Answer

Aavesh Yadav picture Aavesh Yadav · Dec 8, 2017

On BitBucket server, when we get any conflict while merging any pull request, we can use git bash tool to resolve it on our local system and then we can commit and push our changes to remote feature branch and merge it to main branch.

Following steps need to be followed in order in our local system’s git bash tool.

(1) Open git bash tool and checkout or switch to your local feature branch.

(2) Pull the latest changes from the main branch (say 'master') into feature branch.

git pull origin master

(3) If above command fails due to some local changes then use below command to stash them otherwise move to next step.

git stash

followed by -

git pull origin master

(4) In case of conflict, automatic merge will fail so we need to merge it manually. Use below command to resolve conflicts.

git mergetool

By default, it will display all the available merge tools and one of them will be picked automatically. If we feel we are much comfortable with any other tool then we can also configure that and git will open that tool for us for conflict resolution.

(5) Once the conflicts are resolved then commit the changes into feature branch.

git commit

(6) Push the changes to remote feature branch.

git push

Verify on BitBucket server, now pull request should get updated automatically.

Again try to merge it; in case of no conflict it will get merged successfully.

If it has merge conflict again (if someone has committed new changes in main branch during we were resolving conflict on our local system) then follow the above steps again to resolve them.

We should be able to successfully resolve any conflicts if we have followed the above steps in order.

Thanks, hope it helps.