/Isolate a single folder from an existing repository and add it to another repo, keeping history.txt
Created
October 7, 2019 20:35
-
-
Save alisonspencer/9a3febd8a3cbf7f9d6798d8d45e5e38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Make a fresh copy of both the repo to strip down, and the repo you wish to merge into. | |
In the repo you want to strip down: | |
git filter-branch --prune-empty --subdirectory-filter <subdir of folder you want to keep> <branch to isolate from> | |
You will now have a stripped-down copy of your repo, with all history. You may need to clean up adjacent folders/files. | |
Create a new branch and commit any changes you have made. | |
If this was your only goal, celebrate! | |
If you wanted to merge this folder into a different, existing repo: | |
cd <path of repo to merge INTO> | |
Create a new branch in your repo to merge into for your merging | |
git remote add <arbitrary name for your new folder project> <path to new folder project> | |
git fetch <arbitrary name> --tags | |
git merge --allow-unrelated-histories <arbitrary name>/<branch to merge> | |
git remote remove <arbitrary name> | |
Resources: | |
https://stackoverflow.com/a/10548919/5806755 | |
https://help.github.com/en/articles/splitting-a-subfolder-out-into-a-new-repository |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment