I have a git branch that I have been working on called feature1 with committed code. I realized that I would like to split up some of the new functionality into a new branch called feature2 and remove that functionality from feature1 to keep a clear separation between the features.
I have been trying to figure out a good way to accomplish this so that I can later bring feature2 and/or feature1 into master.
The solution I thought of is to create feature2 branch based off feature1, then delete the feature2 related code from feature1. My fear with doing this is that if feature2 gets merged into master first, then feature1 got merged after, would the “deletes” remove feature2 code from master?
Is there a better way I should do this?
Try this:
Now mark all the commits with “edit” and erase any lines that have no relevant work to feature 1. Save and exit. Now you will be prompted to edit these commits. Add whatever you need and stage it and then
Repeat this process until the rebase is complete.
Apply the same steps as before for feature2. After this you will have your 2 separate features and a branch pointing to where you had them both together.
To add:
There is another way to accomplish this.
Now use checkout and or cherry pick to make the branches. This is a more manual way of getting the exact trees that you want for each commit. Of interest is the patch option for add and reset. Also this syntax for git checkout is useful in this situation:
Git gives you many ways of accomplishing what you want. Depending on how isolated your commits are, you may choose one method over another.