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

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

Evan Hein September 28, 2016

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 because by the branch permissions!

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

2 answers

1 vote
Julius Davies _bit-booster_com_
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.
May 9, 2017

I would use a "git merge --squash" to resolve the conflict, but it's a little tricky, because you merge into your local machine's "origin/master" but then force-push the result back to the feature branch.

Here's the steps (assumes branch you want to merge is known as "origin/feature/BRANCH_WITH_CONFLICT" on the server):

git fetch
git checkout origin/master
git merge --squash origin/feature/BRANCH_WITH_CONFLICT
... resolve conflict here ...
git commit
git push origin +HEAD:refs/heads/feature/BRANCH_WITH_CONFLICT

# Note: the + is a shorthand for "--force".

(Yes, I do this all in "detached head" state).

The downside:  several commits get squashed into one.  Maybe you didn't want that.

Another thing to consider:  "origin/feature/BRANCH_WITH_CONFLICT" will no longer "git pull --rebase" nicely if others are still working on it.  You need to get everyone that has work in flight against this branch to do "git reset --hard origin/feature/BRANCH_WITH_CONFLICT" and then cherry-pick their work back onto it.  But probably this is an unlikely problem, since you were trying to merge it into master....

The upside:  you have a new branch with the important you work you needed, and it's now conflict-free and ready to merge via the PR screen.

 

1 vote
Jobin Kuruvilla [Adaptavist]
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 28, 2016

You need to resolve the conflict on the feature branch. i.e. merge from main branch to you feature branch and resolve the conflict on feature branch.

After the resolved code is pushed to remote feature branch, the PR will be updated without conflicts. You can then merge the feature branch.

eranamitai May 9, 2017

I encountered the same problem, and I understand your answer. It would work technically, but my problem is that our feature branches are branched off master and then merged into the ongoing development.

If we merge target (development) into the feature branch, then I cannot later merge it into master if we decide that the change needs to go up as a hotfix.

I guess the only solution is to create a special branch off the feature branch, do the merge there, push it, then pull that branch into development?

Jobin Kuruvilla [Adaptavist]
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.
May 10, 2017

Yes, that can work. Or, you can directly resolve conflicts in the development branch, only when the merge issue is while merging to the deevlopment branch. That would require you to allow pushes directly to the development branch. It is a different workflow when compared to master. What you mentioned is the ideal route but that is a bit more work for developers (creating the extra branch, PR etc).

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events