That way involves a lot of merging work, one merge for each commit.
You can avoid all of that work by instead using the git checkout branch -- file usage.
E.g. you'd like to merge feature/foo onto master using a single commit:
git fetch origin master
git checkout -b feature/foo-squashed origin/master
rm -rf *
git checkout feature/foo -- .
git commit -a
git push origin feature/foo-squashed:feature/foo