Friday, May 19, 2017

Extracting a git subdirectory to a new repository

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