Somehow for me, the accepted answer only runs the first time. Re-doing it throws errors.
I solved it by running the commands below:
git checkout --orphan gh-pages
git --work-tree build add --all
git --work-tree build commit -m 'gh-pages'
git push origin HEAD:gh-pages --force
git checkout -f master