This is probably a very common scenario but to the best of my efforts I couldn’t find any proper answer on it using Google search or use of an LLM chatbot.
This is a team project, I was developing on my sub branch called "devel". I did 6 commits, finally reached a stage where I can push to production so I pushed my changes. On the main branch, using Gitlab’s GUI, I created a squashed merge request.
I continued developing on the same branch locally, did a fix, pushed it, created another merge request but Gitlab blocked the merge with this:
So I pulled origin main, tried ff which fails, then tried rebase, merge and finally cherry pick but the all of them want to do 6 stages of rebase/merge/cherry-pick!!! This is totally unexpected. How do I make it understand to not apply those squashed merges from main to my devel branch? Do I have to delete the devel branch at this point and create a new branch to continue with my development? I’d like to have my commit history though.
So my question is how to resolve the Gitlab error and simply make a proper merge request to apply the last commit on devel branch to main branch.
>Solution :
I continued developing on the same branch locally
That was your mistake. You should never do that. Specifically, once you have done a squashed merge request from a branch, you should abandon (delete) that branch. The reason is that a squashed merge is not a merge, so the commits that you "merged" are all new since the merge-base (the point where you created devel); they are not the same as the six commits that are still sitting there in your branch. Therefore they can conflict with things you’ve done as you’ve continued work on your branch — as you’ve now discovered.
The correct approach is to abandon this branch. Fetch, and make a new branch at the end of origin/main (the main branch as it now stands). Enact your new changes on top of that. Now you will have something that can be merged cleanly.
