Reputation: 35734
I created a feature branch that was cut from develop.
Another developer cut their feature branch from master.
I want to merge my feature branch into their feature branch but it is not acceptable to take the changes from develop also.
All branches have been pushed.
Essentially i want my branch to have been cut from master and not develop.
How can this be achieved?
My first thought is that maybe some use of rebase but I dont know how to do it.
Upvotes: 4
Views: 347
Reputation: 90306
It is still possible to rebase your branch, even if it has been pushed, changing its starting point from develop
to master
. It will however require to force the push if you need to publish it, and other developers will have to redo a fetch or pull.
To do so, checkout yourbranch
, and do
git rebase --onto master develop
You'll then be able to merge both branches, as they have the same starting point the merge will be cleaner, and force push the result. If you don't need to push yourbranch
, but rather merge it back into master
, a simple push of the master
branch will suffice.
Also if you want strict development history it is generally not a best practice to merge two independent feature branches together. If your branch really needs the other's commits, a better alternative is to wait from one of the branches to be merged back to master
.
Upvotes: 4
Reputation: 14501
Note: This solution presumes that you haven't any *.patch files in your project root.
Next commands will extract all commits which are in the my-feature branch but not in the develop branch into patch files:
git checkout my-feature && git format-patch develop
Switch to their-feature branch and cherry-pick your commits from patches:
git checkout their-feature && git am -3 *.patch
-3
parameter is for fallback to 3-way merge if you'll get conflicts.
Upvotes: 2