Let's say there is repo-source that has sub-directory z under x/y which we want to move to repo-target:
- go to source repo -
cd repo-source - extract files from
zinto a new branchz-only-git subtree split -P x/y/z -b z-only
Now if we checkout to z-only branch all files from x/y/z will be in the root directory.
In order to preserve original directory structure move directories/files into x/y/z manually:
- re-create
x/y/zdirectory -mkdir -P x/y/z(mkdir x\y\zon Windows) - move files into it -
git mv <file-to-move> x/y/z - remove unneeded files -
git rm <file-to-remove> - add files to the index -
git add . - commit changes -
git commit -m "Prepare files for moving into repo-target"
Now we need to pull our files from branch z-only in repo-source into repo-target:
- go to target repo -
cd repo-target - add
repo-sourceas a remote repo forrepo-target-git remote add repo-source <path-to-repo-source> - verify it was added -
git remote -v - checkout to a new branch
adding-z-files-git checkout -b adding-z-files - pull files from
z-onlybranch inrepo-source-git pull repo-source z-only --allow-unrelated-histories