How to prevent remote merges of PR's when merging another PR
Asked by jploureiro:

Hi there,

Our team has recently implemented a gitflow strategy for managing our code base. In simple terms, the strategy is

1. Create feature branch from develop branch
2. Checkout feature branch to local copy
3. Development fase
4. Git add \<changes\>
5. Git commit -m "Message"
6. Git pull origin feature/branch
7. Git push origin feature/branch
8. Git checkout develop
9. Git pull origin develop
10. Git merge feature/branch
11. Git push origin develop
12. Developer creates PR to release branch and awaits for approval

As you can imagine, after a while, theres a set of Open PR's in BitBucket to be merged into release branch. Each related to different feature branches.

Then, one developer, due to a hotfix, for instance, merges a specific feature branch to that release branch and some of the previous PRs get merged also with the message that \<developer\> remotely merged \<feature\> into \<release\>.

And that's not really the intention here. We should be able to merge ONLY the specific branch intended to.

Can you please assist in what are we doing wrong?

Many thanks.


Answers:
author: Hana Ku?erov?
body: Hi [@jploureiro](/t5/user/viewprofilepage/user-id/4227335) ,

welcome to the Atlassian Community!

I would suggest you change the way how you handle hotfixes - process them differently using another branch like is described [here](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) - basically create hotfix/xxx branch from the master branch and merge there the changes (if you want to do the code review, use pull request). Then merge the hotfix branch to master and develop.

comments: author: jploureiro
body: Hi Hana,

Thank you for the reply.

That's exactly what we're doing. We're creating a hotfix/xxx branch from master. The problem occurs when we have to merge this branch back into the infinite branches (develop and quality).

The issue here is not with the hotfixes. It was just an example. Even feature branches, when we try to merge one specific branch into 'quality', some of the open PR's are remotely merged as well. This is the problem.

Thanks again.


author: Hana Ku?erov?
body: Hi [@jploureiro](/t5/user/viewprofilepage/user-id/4227335) ,

sorry for the misunderstanding. What you describe is really strange behavior. I believe the auto merge happens, if all the commits from the pull request are also in the merged pull request. Is it possible there are some dependencies between feature branches? It would be great, if you could somehow share commits to be able to see all the history of involved branches...

Is there any specific reason why you are creating pull requests to the release branch? Usually it is done against the develop branch and then everything from develop is released.


author: jploureiro
body: Hi Hana,

No problem, thank you for the reply.

I'm not quite sure if I fully understand what you mean but I'll try to respond. For instance, when you say "if all the commits from the pull request are also in the merged pull request", how could one commit be in 2 different pull requests? What we usually do is only one commit per feature branch and, when done, immediately create a PR to the release branch.

Another thing "Is it possible there are some dependencies between feature branches". I don't think so. Every developer updates the same code base in each feature but I don't think that is creating a dependency.

How can I share the commits with you?

We also merge every feature branch to develop, but we need the release branch because we can not release everything in develop since there's work in progress that can not be released just yet.

Sorry for all the doubts but this process is relatively new for the team.

Thanks again.


author: Hana Ku?erov?
body: Hi [@jploureiro](/t5/user/viewprofilepage/user-id/4227335) ,

thank you.

"how could one commit be in 2 different pull requests?" It is possible, for example if one feature branch is created from the second feature branch, when there are already some commits. That's why I've asked about the branches dependency. But it doesn't seem to be your use case.

If your create some blank test repository - are you able to reproduce this behavior?

Maybe if you can share commit graph for all involved branches, it would help determine, where the problem could be.


Tags: bitbucket-server

server