Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alisonspencer/9a3febd8a3cbf7f9d6798d8d45e5e38e to your computer and use it in GitHub Desktop.
Save alisonspencer/9a3febd8a3cbf7f9d6798d8d45e5e38e to your computer and use it in GitHub Desktop.
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