The following command leaves only content of my/sub/dir
in a master
branch:
git filter-branch --subdirectory-filter my/sub/dir --prune-empty master
as a side effect, my/sub/dir
becomes a root directory of a repository.
Full documentation on git filter-branch
command could be found here: https://git-scm.com/docs/git-filter-branch