For anyone else arriving here in 2021 (or later), git filter-branch is not strongly recommended by the core git team.
WARNING
git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave you with little time to investigate such problems since it has such abysmal performance). These safety and performance issues cannot be backward compatibly fixed and as such, its use is not recommended. Please use an alternative history filtering tool such as git filter-repo. If you still need to use git filter-branch, please carefully read SAFETY (and PERFORMANCE) to learn about the land mines of filter-branch, and then vigilantly avoid as many of the hazards listed there as reasonably possible.
Instead the recommended tool is git-filter-repo which makes easy work of this problem
git filter-repo --path subfolder/ # Filter the repo to just the sub-dir
git mv subfolder/* . # Move the contents of the sub-dir to the root
git commit -m "Filtered from main repo"