This question is somewhat similar to How to combine two branches from two different repositories in a single repository?.
However, I want to combine two branches from the same repository into one branch, but in separate subdirectories. So, starting with one repo that has two branches:
/appFoo
-MasterBranch
-OtherVersionBranch
And ending up with a repo with one branch(master) and two subdirectories:
/appFoo
/MasterSubdirectory
/OtherVersionSubdirectory
And of course I’d like to keep the histories intact, so if I view the log of a file in OtherVersionSubdirectory I see all the commits that had been made to that branch.
Basically what started as a development branch evolved into a custom version for another customer, and so we don’t feel that treating it as a branch of master makes sense any more.
Thanks everyone!
Switch to branch
MasterBranchand throw the contents of the branch into directoryMasterSubdirectory, commit:This leaves your branch with just one dir.
Do analogically in OtherVersionBranch:
Merge one branch into another
Now you have a single branch
MasterBranch. You can merge it withmasteror do whatever you want with it.Alternatively, you may want to replace merge with rebase, if you don’t mind history rewriting. This will produce a cleaner order of commits – first one branch, later the other.
And do try this on a copy. It worked for me, but my case was very simple.