I need to move a subfolder out into a new git repository and then re-add it as submodule to the original repo and preserve original directory structure. Github help suggest to use
git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME to filter original repo which preserves history related to this folder, etc. However this approach is not complete, good to filter out this dir and its history from original repo and re-add it as submodule at the point in history directory was created.
I have following directory structure:
/ /lib /mylib /server /src /tests LICENSE README.md Command
git filter-branch --prune-empty --subdirectory-filter lib/mylib master moves sources to the root of new repo which is not what I want. Same for upper directory:
git filter-branch --prune-empty --subdirectory-filter lib master keeps mylib dir in filtered repo (but potentially could grab other libraries - not my case for lucky) and work a little bit better. So what are next steps:
- Filter out
/lib/myliband its history from original repo to reduce repo size and improve its structure (simple way just remove it and re-add as submodule). - Re-add
/lib/mylibrepo as submodule to preserve directory structure - Good to re-add 2nd on the point in history when
/lib/mylibwas created to keep repo consistent and sources build-able on any stage (or it has no sense?).
Hard to do? Any thoughts?