XXX
|- .git
|- (project files)
YYY
|- .git
|- (project files)
YYY
|- .git <-- This now contains the full change history from XXX
|- ZZZ <-- This was originally XXX, now a subdirectory of YYY
|- (project files)
|- (project files from YYY)
Run the following commands inside YYY to import XXX as a subtree:
git remote add XXX_remote <path-or-url-to-XXX-repo> # Add XXX as a remote
git fetch XXX_remote # Fetch history from XXX
git merge -s ours --no-commit XXX_remote/master # Merge without modifying YYY's files
git read-tree --prefix=ZZZ/ -u XXX_remote/master # Move XXX into subdirectory ZZZ
git commit -m "Imported XXX as a subtree." # Commit the changes
git remote rm XXX_remote # Remove temporary remote
git push # Push changes to the repository
- Preserves full commit history of XXX.
- Places XXX’s files inside
ZZZ/
within YYY. - Does not modify YYY’s existing files during the merge.
Doesnt keep file histories