How to use git-filter-repo to merge one repo as subdirectory into another

Replace the filter-branch command in the script

git filter-branch -f --prune-empty --tree-filter '
        mkdir -p "${REPO_NAME}_tmp"
        git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp"
        mv "${REPO_NAME}_tmp" "$REPO_NAME"
    '

with this

git filter-repo --to-subdirectory-filter "$REPO_NAME"

See Path shortcuts section here

--to-subdirectory-filter <directory>

Treat the project root as instead being under <directory>

Equivalent to using --path-rename :<directory>/


This looks like a path-rename, as part of the path-based filters:

cd  $REPO_DIR_TMP
git filter-repo  --path-rename /:${REPO_NAME}_tmp/

That would rewrite the history of the second repo in a subfolder (within that second repo)

Then you can add it as a remote of the first repo, fetch and merge, as in your gitst.