This is a short guide on how to put all files from a Git repository into a folder in another Git repository.
-
Go the subrepo (
REPO1), switch to the branch you want to merge, and make a new temporary branch.cd REPO1 git checkout BRANCH_TO_MERGE git checkout -b TEMP_BRANCH -
Move the files you want to relocate into a subdirectory within the same repository.
mkdir TARGET_SUBFOLDER git mv * TARGET_SUBFOLDER git commit -m "Move files to the target subfolder"
The file structure has to represent what the target repo should look like after the merge (only in terms of the merged subrepo).
-
Create a bundle of the branch that contains the moved files.
git bundle create ../repo1_bundle TEMP_BRANCH
-
In your target repo (
REPO2), fetch the bundle and create a new branch from it.cd ../REPO2 git fetch ../repo1_bundle TEMP_BRANCH:NEW_BRANCH -
Merge the changes from REPO1 into REPO2.
git checkout master git merge NEW_BRANCH --allow-unrelated-histories
-
Clean up by removing the temporary branch and bundle.
# Clean up REPO2 git branch -d NEW_BRANCH rm ../repo1_bundle # Clean up REPO1 cd ../REPO1 git checkout BRANCH_TO_MERGE git branch -d TEMP_BRANCH