I want to resolve a git merge conflict (between feature and test branches), but there are some limitations:
- cannot push directly to test and master branches
- cannot merge feature branch into the test branch (because I cannot push to origin test)
- cannot merge test branch into the feature branch (because later, when it is tested I should merge feature branch into the master branch)
- the conflict is caused by the test branch NOT the master branch
- I want to avoid duplicating branches
- cannot resolve conflict on Gitlab UI, because it merge the target branch (test) into the source branch (feature) after resolving
The workflow of my team is the following:
- every feature branch must be based on master branch
- commit/push the feature branch then create a merge request to test (default) branch (then wait for testing)
- create a merge request to master branch
I tried with these workarounds:
- turn off the "anti-push" constraint temporarily (if there are a lot of conflicts, this is not ideal)
- turn off the "anti-push" constraint permanently (I do not want this...)
- using duplicated branches (I do not want this, because it is confusing)
- using Gitlab UI (break my workflow, mentioned above)
- manually edit the feature branch (does not work, because it is not a "real" merge)
I think I cannot use git rebase, because the conflict is not caused by the master branch, and I want to preserve the "master based" feature branch, so I also cannot use rebase based on test branch.
In few cases, this solution can solve the problem, but not in my case.
I am looking for a "simple" solution which resolve the problem above. Temporary branches on local (but not on remote) are okay.
Heavily Updated Answer
After reading the problem more closely and also agreeing with sentiments expressed by @j6t I need to alter my advice... this workflow as a whole is problematic. Don't do what I said ( don't branch feature from
test). Branch from master, then make a variant of the branch calledfeature-testwhich you create in case of a conflict by doing one of the two conflict resolution paths i mentioned ( merge feature into test, or test into feature and resolve the conflicts ) and that branch can be requested for merge totest.. if items come up make fixes to your initial branch and then merge that branch intofeature-testagain. this way you keep fixes found from testing infeatureinfeatureand you keep conflict resolutions infeature-test, so that in the end you can mergefeaturetomaster, with stronger safety that fixes of issues fromfeature's testing are infeaturebut not conflict resoultion or stray materials fromtest.My big issue with this is that
testshouldn't generally exist or be used. They should test your branch by mergingmasterinto it and testing it. Otherwise what you are testing is not what you are merging to master, and it doesnt sound like testing is performed on master.Now if you have a bunch of related features, or you have a big change such that other things SHOULD be aware of and take account for it things change. In that case you should use an integration branch that you merge into for testing, and you should potentially branch off the
integrationbranch for the features that are targeted for theintegrationbranch, which will all go tomastertogether.Overall if
testis not merged tomasterbut you test off of it, and you keep fixing things ontestyou end up in a wierd state where you aren't testing what will actually go tomasterwhich could both hide and introduce bugs that you would otherwise catch in testing.Some things I said before still hold:
There is no SIMPLE solution for resolving merge conflicts; you have to resolve them manually otherwise git would have done it for you.
The workflow and constraints make this a horrible situation. They are effectively testing a branch can significantly vary from what master will be.
I honestly don't see value from the
testbranch currently, iftestis not merged tomasterand viceversa, and only see negatives stemming from it.Personally if this was the workflow I was presented with I would be discussing changing it, or heading toward a new job unless there is significant test automation that is carried out by CI/CD before the branch is allowed to merge to
master. It's a recipe for disaster. You're going to constantly be wasting time crafting conflict resolutions to be able to merge totestthat are thrown away, and then possibly doing different resolutions to merge tomaster.The testers should do their testing and have automation in place on your branch once its PR is opened to be merged to master. They should mark it passed when they have validated it. I would do this by having two different sets of gatekeeper approvals required for the merge to master, someone from code review group, and someone from qa ( if that can't be done via CI/CD ).
masteronce afeatureis both validated (reviewed and tested) and desired to be brought intomaster.featureis validated and sits because it's not yet wanted inmaster, than it sits there ready and waiting.featureafter testing, the testing needs to be verified again (this is why automation/CI/CD is best), and someone should update the code review to approve it again.mastercommits to make sure that if something is independently added tomasterthat didn't conflict withfeaturethat the two both being present doesn't cause a problem.It also boils down to goals: should
masteralways be deployable? Or should it always be buildable, mostly stable, where you work from, and periodically you cut a release frommasterthat has been more deeply tested? ( In which case you should absolutely tag a release commit so that patches can be created on top of the released version, and then ported/merged/cherry-picked as needed tomaster. There is no right or wrong answer to this question. Different projects/workflows and scenarios have different requirements.