This sentence gets it:
In general, the way to get the best of both worlds is to rebase local
changes you’ve made, but haven’t shared yet, before you push them in
order to clean up your story, but never rebase anything you’ve pushed
somewhere.
Source: 3.6 Git Branching - Rebasing, Rebase vs. Merge