Error: refname refs/heads/master not found


I am trying to publish my third site, so I fairly new to github, and I am getting: the following error:

$ git branch -M main
error: refname refs/heads/master not found
fatal: Branch rename failed

I have used git-bash, them some code on github account, and on the above stage I got the error.
I am bit stuck, I have search for the error, but I could not fix it.

Did you solve the problem ? I take that error too and couldn’t find solution

Could the branch possibly be named main already? Github changed the default name for the default branch from master to main a while ago.

Can I post the link to the solution here? Its an external source… and its in Portuguese:

Basically what I did was to run the

git fetch
git reset --hard origin/master

them git push