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?
To add branch permissions to a repository: 2- Choose Settings > Branch permissions. 3- Click Add a branch permission. 4- In the Select branch field, select either By name or pattern or By type. 5- In the Write access field, add the users and/or groups who can push or merge changes to the branch.
You'll need to update your branch with new commits from master, resolve those conflicts and push the updated/resolved branch to GitHub.
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.
When we get into the dirty automatic merge scenario, whether by branch permissions or by automerge conflicts, using feature/bugfix branches, we do the following:
In your local clone of the repository:
Here it is on the CLI:
git checkout <destination branch>
git pull origin <destination branch on remote>
git checkout -b feature/<my branch description>
git fetch origin <source branch>
git merge FETCH_HEAD
<fix conflicts>
git stage <changed files>
git commit -m <my message>
git push origin feature/<my branch description>
<continue in bitbucket>
The instructions, unfortunately, come a bit unstuck with certain combinations of permssions, and it's something we hope to fix sometime (I work on Bitbucket).
To get around the issue you can resolve the conflicts on the source branch by merging changes in from the target branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With