git push: "error: src refspec main does not match any" when local branch is master (or no commit yet) - run git branch -m main, then git push -u origin main
Rename the local branch with git branch -m main and then git push -u origin main (or push without renaming via git push origin master:main). Reproduced against a local bare remote on git 2.43.0: in a repo made with git init (no init.defaultBranch set, so the branch is master), git push origin main printed error: src refspec main does not match any followed by error: failed to push some refs to '../r3.git', exit code 1. The same error appears both before the first commit and after committing on master, because no local ref named main exists. After git branch -m main, git push -u origin main printed * [new branch] main -> main and branch 'main' set up to track 'origin/main'; git push origin master:main also worked in a separate repo and created main on the remote.