Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rebase sub branch from main after main got a squashed merge

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

gitlab

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading