4

Scenario:

I have a production (P) branch and my current (C) branch I created to work on some new features. Some of them are ready, however work on the rest will take more time than anticipated.

I would like to push to production (and merge with production (P) branch) features that are ready now, and then continue to work on the rest of them in my current (C) branch.

My Idea:

I can create new pre-production (PP) branch, remove all references to the code that is not ready in it and merge it to production (P) branch. Then I'll continue to work on current (C) branch and merge to production (P) branch when my work is ready.

Problem:

When I remove references in pre-production (PP) branch, there will be a lot of conflicts later when I merge my current (C) branch with production (P) branch. I'm afraid I can miss some important change in code. How can I do it better, avoiding conflicts? Merging is the power of Git, so my assumption is I don't know something important.

4

You have made a mistake in your git flow and nothing elegant is there to salvage you anymore. Rather than trying to remove stuff from a branch created from C, the better solution is to create the PP branch from your P branch and cherry-pick the C branch into the new branch PP.

git checkout production
git pull
git checkout -b pre_production
git cherry-pick ...

Why? In your case you are going to have to go over the code in the branch C anyway and using your approach you would have to decide what's to be removed and what's to stay.

The solution for future cases, make your branches more feature oriented, that way you can only merge the features you really want.

  • yep, I should branch much sooner. it just started small and then I missed the critical point ;) but cherry-picking! that's exactly what I was looking for! :) – rsm Mar 7 '17 at 22:54
  • Boom! Great ideas. – wogsland Mar 8 '17 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.