I got the same error and I fix it with the next steps
git branch -M main
git remote add origin https://github.com/username/proyect-name
git push -f origin main
after that I did another commit and push normally I mean like this
git add .
git commit -m "Another commit"
git push