I use git-trim for that:
https://github.com/foriequal0/git-trim
Readme also explains why it's better than a bash-oneliner in some cases.