I find that after I implement a bunch of features, I look at the code and do a refactoring pass. It seems like it makes sense to do that kind of feature work on a branch? I don't know that you need to keep the branch history though, so maybe it could entirely rewritten or squashed?
Messy personal branch, pushed to a feature branch, squashed when merged with dev, bugs found in dev squashed when merged with main.
Seems to be the standard in shops with competent git users and no culure established around other version controll systems. What the commit messages are is fluid. My messy personal ones tend to be "start/end of day commit."