Search code examples
gitgit-history

How to get all commit releated to a folder and put it into new repo?


I have a git repo like

repo
/sub-project1
 /sub-folders and files
/sub-project2
 /sub-folders and files
/sub-project3
 /sub-folders and files

i want to remove

 /sub-project1
     /sub-folders and files

and create a new repo with all the git history related to that folder and files need to be also included.

main consideration is keep only the history related to that folder only and remove all other unwanted history

what is the best way to do it?


Solution

  • keep only the history of the desired folder. need to use following command

    git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter <folder-name> -- --all