Jump to the navigation menu

Extracting a custom module with a Git subtree

To extract a directory from a repository and keep the history, you can use the git subtree split command to create a new branch:

git subtree split --prefix=web/modules/custom/my_module --branch=split
Created branch 'split'
17835f24069061326e9e065f076afd67434e1b2f

This will create a new branch with just the contents of the given directory.

This can be pushed to a different repository:

git push [email protected]:opdavies/new-repo.git split:main

About me

Picture of Oliver

I'm an certified Drupal Triple Expert with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.