merge 2 repos with "inverse" folder structure and preserve branches
===

I've read enough about basic merging of 2 different repos, but I have some scenario, which is more complicated, than basic examples.

We have 2 completely different repos:

 - /folder/ - repo1
 - /folder/project/ - repo2

`repo1` is located on our own server and have only `master` branch
`repo2` is located on github and have several branches.

I need to move everything into `repo2`, and fulfill the following conditions:

 - preserve file structure. Moving (changing *final* structure) folders is not an option
 - preserve branches from repo2, but modify all of them in the same way: move repo root up one level and add files from repo1.
 - commit history for repo2 should not be lost. History from repo1 may be merged (the best) or even discarded.
 - won't need to use repo1 anymore and have any remote refs for it.


    /folder/ (master) - repo1
    /folder/project/ (master, dev) - repo2
     -->
    /folder/ (master, dev) - repo2

I.e. need to merge not a subtree, but _suptree_ %-)

I have thought about 2 options:

----------

Use subtree merging as written in [that manual][1], but do that a bit different and with several branches, like:

    $ git checkout -b repo1_new_dev
    $ git merge --squash -s subtree --no-commit repo2_dev

    $ git checkout -b repo1_new_master
    $ git merge --squash -s subtree --no-commit repo2_master

And then manually move repo1 into repo2. Or at least, copy repo1 into repo3, delete repo2 [and rename repo3 into repo2].

----------

Another option is do the following for each branch in repo2:

 - `mkdir project` (yes, `/folder/project/project/`)
 - move everything there and commit it (need to be sure git would understand files were just moved, to make later merging easier).
 - merge repo1-master as subtree (or recursive as in [that answer][2]) into root dir
 - commit it again

And then just copy files one dir level up.

    ls -1 /folder/project/* | grep --invert-match project | rm -r
    mv /folder/project/project/* /folder/project
    rm /folder/project/project/

----------

These are viable ones, but seemed a bit complicated and I'm not sure I won't lost commit history. Are there any better solutions?

  [1]: http://git-scm.com/book/en/Git-Tools-Subtree-Merging
  [2]: http://stackoverflow.com/a/3632126/255363