From time to time, i need to do this as git repositories are rarely left untouched during their lifetime.
It appears that it quite simple exercise, but i keep forgetting the command to use.
So, ultimately if i want to extract the directory let's say 'core' from the current git repository i have to run the following code:
git filter-branch --prune-empty --subdirectory-filter <directory_name>
For example:
git filter-branch --prune-empty --subdirectory-filter core