Reproduced on Git 2.50.1 with a local test remote: all three situations below printed error: src refspec main does not match any, then error: failed to push some refs, and exited 1.
Before the first commit the branch is unborn: git init names it, but it does not exist as a ref until something is committed. Commit first, then push.
If the repository was created with master as its default branch, there is no main to push. Either push master, or rename it with git branch -M main and push that. Both worked in the reproduction.
In CI, a checkout of a single commit has no local branch at all. git push origin HEAD:main pushes the current commit to the remote's main and worked from a detached HEAD.
A nearby first-push error: git remote add origin URL on a repository that already has an origin prints error: remote origin already exists. Use git remote set-url origin URL to change it instead.