Merge form one protected branch to another protected branch

Till about two months ago we were living without feature branches in our organisation, so all PRs went to Development (read: our master) which is protected branch. Live was easy.

Today we have feature branches, for example feature/SPEC-A_Something. This is a protected branch where contributors PR their changes. That works perfectly to the moment, were readjustment of the feature/SPEC-A_Something branch to the Development is reqired.

  • If we PR Development to feature/SPEC-A_Something and there are conflicts, how we can solve them not using the GitHub website? They can be complex, and they require builds and unit test runs, before could be committed. Is it even possible?
  • If we create a branch in fork, then do the merge of Development and then PR it requires much more work and leaves some uncertainity of the source of changes on the PRed branch. Do we have to stick to that?

Thanks in advance for any advice.

1 Like

By default, protected branches are protected from:

  1. Being deleted
  2. Being force pushed to

On top of this, you can enable other protections. Without knowing what the exact configuration is of your protected branches, it is hard to answer your questions with any certainty. I’ll assume that you’re requiring that status checks pass before merging a PR since that is one of the more common protections enabled and answer your questions based on that assumption.

Your first question, if you create a PR and there are conflicts, how can you solve them without doing it through the GitHub website? There are standard Git flows that you can use to resolve merge conflicts. But what GitHub shows you isn’t really a merge conflict. It is more of a “merge conflict preview” because it is telling you that by merging the PR as-is, it will create a merge conflict and it is suggesting that you change your PR so that the merge conflict doesn’t occur. One of the easiest ways to do this is to merge the current contents of the PR’s base branch, the branch being merged into, into the PR’s compare branch , the branch whose changes are being merged. This allows you to resolve the conflicts on the compare branch locally, push the latest changes to the compare branch on GitHub, and then merge the PR after all status checks pass.

As for your second question, I’m not sure exactly what flow you’re describing or what your concerns are. Ultimately, the question is “Do we have to stick to that?” The answer to that question is almost always “no”. Do whatever works best for you and your team :grinning: But I’d like to know more about the challenges you’re running into before I give a definitive answer. Can you give some more details?

I hope that helps!

1 Like

@lee-dohm wrote:
[…] One of the easiest ways to do this is to merge the current contents of the PR’s base branch, the branch being merged into, into the PR’s compare branch , the branch whose changes are being merged. This allows you to resolve the conflicts on the compare branch locally, push the latest changes to the compare branch on GitHub, and then merge the PR after all status checks pass.

Is it going to work if both are protected? The protection we have enabled (sorry, I don’t manage this organization repo) doesn’t allow any direct push. Will GitHub let such merge in?

As for your second question, I’m not sure exactly what flow you’re describing or what your concerns are. Ultimately, the question is “Do we have to stick to that?” The answer to that question is almost always “no”. Do whatever works best for you and your team :grinning: But I’d like to know more about the challenges you’re running into before I give a definitive answer. Can you give some more details?

Our normal flow:

  1. Create a work branch on local fork for job from JIRA card
  2. Commit & push work
  3. PR that branch to Development
  4. Address review comments by more pushes to the work branch
  5. Squash & merge when PR is approved

That’s dead easy!

Our modified flow:

  1. Create a Feature Branch on GitHub from selected commit on Development and protect it
  2. Create a work branch on local fork for job from JIRA card (with tip of the feature branch as baseline)
  3. Commit & push work
  4. PR that branch to Feature Branch
  5. Address review comments by more pushes to the work branch
  6. Squash & merge to Feature Branch when PR is approved
  7. Repeat until epic for the Feature Branch is finished

However, when time required to get the epic done is long, we’d like to merge Development to Feature Branch from time to time. Currently person doing so creates a branch about the merge, do the merge, resolve conflicts, then PR… and bang! By default PR is directed to Development, so we need to be very careful here!

This process is tedious - it would be simpler if we can just directly PR Development -> Feature Branch, but we don’t know how to avoid protections to blow us in the face in case of potential conflicts to resolve.

Am I correctly understading the command line instructions provided by GitHub would let us do it safely even if both branches are protected? Am I correctly understanding that any person in the team can do that not only the creator of the PR?

@michalfita wrote:


 

Is it going to work if both are protected? The protection we have enabled (sorry, I don’t manage this organization repo) doesn’t allow any direct push. Will GitHub let such merge in?

Typically, the administrators of the repository can still push to branches that are protected from normal pushes. So if it is configured in such a way that a typical user can’t push changes, then an administrator will have to do it. If an administrator is restricted from maintaining the branch as well, then your repo administrators may want to consider relaxing the protections slightly.

@lee-dohm wrote:


Typically, the administrators of the repository can still push to branches that are protected from normal pushes. So if it is configured in such a way that a typical user can’t push changes, then an administrator will have to do it. If an administrator is restricted from maintaining the branch as well, then your repo administrators may want to consider relaxing the protections slightly.

So, you confirm we can’t do it without intermediate branch and PR of that branch. Administrators are out of the equantion - the only one is our manager, not normally involved in any development activity.

I had slight hope there is a way to handle that smarter.