From 55c4c32887bd6117d0fec0f3536dd57b1c0ef216 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 4 Sep 2024 20:12:00 +0100 Subject: [PATCH] Extracting a custom module with a Git subtree --- source/_notes/21.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 source/_notes/21.md diff --git a/source/_notes/21.md b/source/_notes/21.md new file mode 100644 index 0000000..c9401a6 --- /dev/null +++ b/source/_notes/21.md @@ -0,0 +1,21 @@ +--- +title: Extracting a custom module with a Git subtree +date: 2024-09-04 20:12:00 +tags: [Git] +--- + +To extract a directory from a repository and keep the history, you can use the `git subtree split` command to create a new branch: + +```shell +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: + +```shell +git push git@github.com:opdavies/new-repo.git split:main +```