I'd like to create a new branch in my repo that only includes files from a specific directory in master and its history then push that branch to a new repository.
...or something equivalent – for instance it may be possible to push a directory to a new repository to a new repo without creating a branch.
So far I think the following will work, but I wonder if there's a more streamlined way.
1 - Create an empty branch:
git symbolic-ref HEAD refs/heads/<new-branch>
rm .git/index
git clean -fdx
2 - Checkout a directory from master:
git checkout master <paths> ...
git add <paths> ...
git commit
3 - Push branch to new remote:
git push -u <remote-URL> <new-branch>
4 - Then, in the new repo, merge branch with master:
git checkout -t origin/<new-branch>
git checkout master
git merge <new-branch>
git branch -d afterimage
git branch -d -r afterimage
I'm attempting to do something equivalent to Detach subdirectory into separate Git repository, but without the git filter-branch
mess.