I have a project with a structure like this:
src/
scripts/
db/
other_stuff/
even_more_stuff/
file1
file2
file3
This repository needs to be split up. Folders db and scripts need to be split out into their own repositories, and I know that this can be easily done with git filter-branch --subdirectory-filter ...
I also need to create a new main repository based on the current structure (including history), but excluding anything that is already split to its own repository or any files on a specific list of files to exclude: file1
, file3
, even_more_stuff
. Is there a way to use git filter-branch
to filter out files by specific names?
The resulting main repository should simply be:
src/
other_stuff/
file2
One catch to this is I'm not supposed to make any changes to the original repository, so I can't just delete file
, file3
, etc... and then copy the remainder to a new repository.
OK, here's how I did it using git-filter-repo:
cd my-source-repo
git filter-repo --path src --path other-stuff --path file2
git log
look OK.cd my-target-repo
git remote add src-repo path/to/my-source-repo
git pull src-repo main --allow-unrelated-histories
git remote rm src-repo
git push --set-upstream origin main
(Change branch names where appropriate.)
I've only done this once, so I don't know if there's a shorter, easier way, but this was still better than using git filter-branch
.