This question is similar to this question but I need to understand how the complications of having pushed the new feature to remote.
Essentially I have a branch, new_feature_2
, which I by mistake started developing off of new_feature_1
. I meant to develop new_feature_2
off of main
and now I am trying to rectify my mistake.
From the above link it seems like I should rebase new_feature_2
onto main
in the following fashion.
git checkout new_feature_2
git rebase --onto main new_feature_1 new_feature_2
Now, I would like to extend the question by understanding what I need to do to the remote branch? I had already pushed my new_feature_2 branch to the remote. Is there anything special I need to do here? Or after I complete the rebase, can I just push again?
CodePudding user response:
I had already pushed my new_feature_2 branch to the remote
That's the problem. This now a pushed branch. In some sense, it is a shared branch. But in a larger sense, it isn't! So there's no objection to what you will have to do, which is push with force.
You don't need the initial checkout if you're going to use the full form of rebase
like that (which you should should definitely use). So
git rebase --onto main new_feature_1 new_feature_2
git push -f origin @
Done! (By the way, I left out a possible step; you might want to say git fetch origin main:main
beforehand, just to make sure your main
is as up to date as it can be before the rebase.)