Fix src refspec main does not match any
Verify the current branch and first commit before pushing, then use the actual branch name instead of guessing between main and master.
Git cannot push main when no local ref named main resolves to a commit. This commonly happens in a new repository with no commits, or when the local branch has another name such as master.
Check branch and commit state
git status
git branch --show-current
git log -1 --oneline
If git log says the branch has no commits yet, create the first commit before pushing:
git add README.md
git commit -m "docs: add project readme"
git push -u origin HEAD
HEAD means the currently checked-out branch, so this avoids guessing its name. Review git status and git diff --cached before the commit.
If the branch is named master
You can push the existing branch as-is:
git push -u origin master
Or rename it locally if your project has chosen main:
git branch -m main
git push -u origin main
Renaming a branch does not delete commits, but collaborators and automation may still refer to the old name. Coordinate the change in an established repository.
Avoid the misleading fixes
Do not create empty commits or force-push just to bypass this message. Confirm that the repository contains the files and commit you intend to publish. If git branch --show-current is empty, you may be in detached HEAD state; create or switch to an intentional branch before pushing.
For tracking errors after the first push, see current branch has no upstream.