Skip to main content

git - error: src refspec main does not match any

I made a repo on github and did git init on folder. Then I git remote add origin REPO and git branch -M main. Then I tried git push -u origin main. Error says:

error: src refspec main does not match any
error: failed to push some refs to REPO
None

And git push errors:

fatal: The current branch main has no upstream branch.
None

That all means there is not ONE commit. Without a commit there isn't really existing that branch 'main'.
Sogit add . and git commit. After that git push --set-upstream origin main will work.

Long version: stackoverflow.com/questions/65173291/git-push-error-src-refspec-main-does-not-match-any-on-linux