'How do I proceed with this merge and fork/branch?
(Diagram 1)
At a past commit, I created a Foo branch and made some significant progress on the Foo feature.
Then I checked out main and began developing a Bar feature, so both branches share the same common ancestor. Later I went back to Foo and developed it further and realized that I wanted to take the progress in a different direction.
(Diagram 2)
I would like to achieve the second diagram: the goal is to checkout main, then incorporate both Foo and Bar (order not specific). Semantically I called it a fork because I want to go in a new direction with the project but it's really just a branch that gets all the latest progress.
Both Foo and Bar features certainly have edits to the same files, with possible conflicts.
And the final note is that the "Fork" branch does not need the itemized commits from Foo and Bar branches, just the progress. I think I need to squash?
How do I proceed with creating the new Fork branch and getting all of the progress from the features?
Solution 1:[1]
First, create a branch name for the old bar to hold its place:
git branch old-bar
Now, rebase bar onto foo and then rename bar to fork. First you'll need to determine the point where bar branched off of main:
git merge-base main bar
Write down the first digits of the SHA number of the result. Now:
git rebase --onto foo <SHA> bar
git branch -m fork
Finally, rename old-bar back to bar:
git branch -m old-bar bar
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | matt |

