If you haven't seen, check out my previous shortpost on using josh at LINK_HERE.
My goal : extracting subfolder a
from repo A to merge into repo B into toto/a.
In B :
git remote add A https://$ADDR
git fetch A main
josh-filter ':/a:prefix=toto/a' FETCH_HEAD
# Now the merge part
git switch FETCH_HEAD
git switch -b new-a
# I use rebase to get a linear history
git rebase main
# Merge it to main
git switch main
git merge --ff-only new-a
And voilà! Very useful to keep history. History being in my opinion a very important part of the code.