From this answer: https://stackoverflow.com/a/17141512/6307412
git checkout my-branch
git branch -m my-branch-old # this will rename 'my-branch' to 'my-branch-old'
git checkout master
git checkout -b my-branch
git merge --squash my-branch-old
git commit -m "...your message..."
git push origin my-branch --force # add --force to rewrite history on remote if neccessary