Using the -m option (move/rename) instead of -M with the name of the branch you’re renaming from, here main, will work. Then you can push your renamed branch and maintain your reflog as well.
git branch -m main master
git push -u origin master
I also wrote a blog post with more details which can in case the repo was cloned by someone else before renaming the branch. You can check it out here.