How to fix conflicts on protected branches - GEOS-ESM/MAPL GitHub Wiki

Every so often, there will be conflicts. An example is in Pull Request #27. This was trying to merge master into develop to keep things in sync. But Github noted three conflicts in:

MAPL_Base/MAPL_Generic.F90
MAPL_Base/MAPL_HistoryGridComp.F90
MAPL_Base/MAPL_LocStreamMod.F90

If these branches weren't protected, you could fix the conflict in browser; we cannot, though. Now Github will provide some instructions:

Step 1: From your project repository, bring in the changes and test.

git fetch origin
git checkout -b master origin/master
git merge develop

Step 2: Merge the changes and update on GitHub.

git checkout develop
git merge --no-ff master
git push origin develop

but these instructions are a bit terse. They miss some things you might forget to do. So here is a more explicit procedure to do this using this as an example.

Clone the repository and get the branches locally

First we get the code and make sure we have the two branches we want (master and develop) locally.

$ git clone [email protected]:GEOS-ESM/MAPL.git
$ cd MAPL
$ git checkout master
$ git checkout develop

Now you have what you want locally.

Merge develop into master

This is the step that is kind of weird at first. We want to merge master into develop. But we need to start from the other direction. First, make sure you're on master:

$ git checkout master

Now do the merge like Github suggests:

$ git merge develop
Auto-merging MAPL_Base/MAPL_LocStreamMod.F90
CONFLICT (content): Merge conflict in MAPL_Base/MAPL_LocStreamMod.F90
Auto-merging MAPL_Base/MAPL_HistoryGridComp.F90
CONFLICT (content): Merge conflict in MAPL_Base/MAPL_HistoryGridComp.F90
Auto-merging MAPL_Base/MAPL_Generic.F90
CONFLICT (content): Merge conflict in MAPL_Base/MAPL_Generic.F90
Removing GMAO_pFIO/tests/test_SimpleSocket.pf
Removing GMAO_pFIO/SimpleServer.F90
Removing GMAO_pFIO/SimpleDirectoryService.F90
Removing GMAO_pFIO/RequestIdMessage.F90
Removing GMAO_pFIO/MessageQueue.F90
Removing GMAO_pFIO/MemReference.F90
Removing GMAO_pFIO/CollectionIdMessage.F90
Removing GMAO_pFIO/AddCollectionMessage.F90
Automatic merge failed; fix conflicts and then commit the result.

And as Github reported we have three conflicts. If you do git status, you'll see these as both modified:

	modified:   Tests/ExtDataDriverGridComp.F90
	modified:   Tests/ExtDataDriverMod.F90
	modified:   Tests/ExtDataRoot_GridComp.F90
	modified:   Tests/VarspecDescription.F90

Unmerged paths:
  (use "git add <file>..." to mark resolution)

	both modified:   MAPL_Base/MAPL_Generic.F90
	both modified:   MAPL_Base/MAPL_HistoryGridComp.F90
	both modified:   MAPL_Base/MAPL_LocStreamMod.F90

Fix the Conflicts

Now you need to edit these files and fix them and add them. Look for the <<<<< style conflict markers in your editor.

$ vim MAPL_Base/MAPL_Generic.F90
$ git add MAPL_Base/MAPL_Generic.F90

Edit and git add all the files. Once you are done, commit:

$ git commit

And the editor will have a default message. I usually just keep it, but add more if you like.

Merge master into develop

Now we do the other direction following the Github advice:

$ git checkout develop
$ git merge --no-ff master

Again, an editor will popup. Once you write that, a git status will show some updates for develop:

$ git status
On branch develop
Your branch is ahead of 'origin/develop' by 6 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Now if we are being good, this should have maybe 2 or 3 commits. 6 commits shows we probably haven't been merging master into develop as we should as a hotfix is usually not a series of commits. 👎

Push to Github

Now Github says to just push develop to origin but because develop is a protected branch we can't do that. So make a new branch:

$ git checkout -b merge/mathomp4/handmerge-master-to-develop-2019Aug28

and push that up to github:

$ git push -u origin merge/mathomp4/handmerge-master-to-develop-2019Aug28

and then that is the branch that needs have a pull request into develop!

Confusing, but there you go.

⚠️ **GitHub.com Fallback** ⚠️