This is a mini howto on moving a subdirectory to its own repository retaining history
Assume PARENT
is the original parent Git repository (locally) and CHILD
is the new local repository that you wish to create from a subdirectory, retaining all of its history from the PARENT
repository; PARENT_PATH
and CHILD_PATH
are the paths to PARENT
and CHILD
respectively; SUBDIR is the relative path within the repository under extraction:
git clone --no-hardlinks PARENT_PATH CHILD_PATH
pushd CHILD_PATH
git filter-branch --subdirectory-filter ${SUBDIR} HEAD -- --all
git reset --hard
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
popd
Have fun and ENJOY! @SusanPotter
Heckle me in good spirits on Twitter ;) What Git hacks can you send my way? Cheers!
I'm not sure if I can issue a pull request on a gist. However, you might be interested that I fixed a defect in the script provided; the bare word SUBDIR is used where the variable ${SUBDIR} is required.