Splitting Repository Subfolder / Subdirectory in GIT

I had a GIT repository that I wanted to structure differently.  I have also used this this same technique for splitting up their repositories into submodules.

The quickest approach, in my mind, was to first split out the history of a folder into a new branch:

  • git subtree split -P <name-of-folder> -b <name-of-new-branch-to-store-history>

After that go and create a new repository and pull in all the history from the folder:

  • git init
  • git pull </path/of/original repo> <name-of-new-branch-created-above>

Done with that repository.

Now back in your “original” repository you may want to clean out the history of that folder OR you may not.  In one case, I left the history alone and just deleted the folder.  In another I cleaned out the history because I thought it was redundant for that particular case.

To filter out a folder in the larger/original repository:

  • git filter-branch –subdirectory-filter <folder> — –all

Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *