Distilled from a question thread (which I found a little too confusing) on Stack Overflow. matli writes:
Just to make it clear, I have the following structure:
XYZ/ .git/ XY1/ ABC/ XY2But I would like:
XYZ/ .git/ XY1/ XY2/ ABC/ .git/
See the original thread for details.
Backup
XYZ. I use rsync, just to spread my risk around, but you cangit cloneif you prefer.rsync -ahz --progress XYZ/ XYZ.git.bak/Create the repository you want to be
ABC-only by cloning it fromXYZ.git clone --no-hardlinks XYZ ABCIn
ABC, remove all history outside theABChierarchy.git filter-branch --subdirectory-filter ABC HEAD -- --allClean up references…
git remote rm origin git update-ref -d refs/original/refs/heads/master…and then objects.
git reset --hard git reflog expire --expire=now --all git gc --aggressive git prune git repack -adIn
XYZ, remove all history belonging to theABChierarchy.git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch ABC" --prune-empty HEADAlternatively, if you’re not worried about
ABC’s history cluttering upXYZ, just delete theABChierarchy and commit.git rm -rf ABC git commitClean up: repeat Step 5 in
XYZ.