0

I am creating an app and have been working on the Front-end and Back-end in separate repos. Both have been committed to GitHub.

Now I want to create a new repo called Main and move both Front-end and Back-end repos into the Main repo. I want to keep them separate and not merge them. I also want to preserve the log and commit history of both repos. Both repos have had branches and then merged later into master.

I see posts showing how to merge repos together into one which keeps the histories but I do not want to merge them.

I am not looking for submodules nor are they orphaned branches.

Kathy
  • 97
  • 2
  • 11
  • Related: [stackoverflow.com/questions/1811730/how-do-i-work-with-a-git-repository-within-another-repository](https://stackoverflow.com/questions/1811730/how-do-i-work-with-a-git-repository-within-another-repository) – MisterP Jan 31 '18 at 22:41
  • Possible duplicate of [What are the uses cases for git orphaned branches?](https://stackoverflow.com/questions/13202705/what-are-the-uses-cases-for-git-orphaned-branches) – phd Jan 31 '18 at 23:16
  • Why do you want a new repo "Main" if everything is separated? Are you asking for [`sumbodules`](https://git-scm.com/book/en/v2/Git-Tools-Submodules)? – LinFelix Feb 01 '18 at 01:40
  • Not asking for sumbodules, orphaned branches but thanks. – Kathy Feb 01 '18 at 20:38

1 Answers1

0

Found the answer on this site: https://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/

Merging Two Git Repositories Into One Repository Without Losing File History

The basic idea is that we follow these steps:

  1. Create a new empty repository New.
  2. Make an initial commit because we need one before we do a merge.
  3. Add a remote to old repository OldA.
  4. Merge OldA/master to New/master.
  5. Make a subdirectory OldA.
  6. Move all files into subdirectory OldA.
  7. Commit all of the file moves.
  8. Repeat 3-6 for OldB.

A Powershell script for these steps might look like this:*

  1. Assume the current directory is where we want the new repository to be created. Create the new repository

    • git init
  2. Before we do a merge, we have to have an initial commit, so we’ll make a dummy commit

    • dir > deleteme.txt
    • git add .
    • git commit -m “Initial dummy commit”
  3. Add a remote for and fetch the old repo

    • git remote add -f old_a <OldA repo URL>
  4. Merge the files from old_a/master into new/master

    • git merge old_a/master
  5. Clean up our dummy file because we don’t need it any more

    • git rm .\deleteme.txt
    • git commit -m “Clean up initial file”
  6. Move the old_a repo files and folders into a subdirectory so they don’t collide with the other repo coming later

    • mkdir old_a
    • dir –exclude old_a | %{git mv $_.Name old_a}
  7. Commit the move

    • git commit -m “Move old_a files into subduer”
  8. Do the same thing for old_b

    • git remote add -f old_b <OldB repo URL>
    • git merge old_b/master
    • mkdir old_b
    • dir –exclude old_a,old_b | %{git mv $_.Name old_b}
    • git commit -m “Move old_b files into subduer”
Kathy
  • 97
  • 2
  • 11