git · Git
The message
error: src refspec main does not match any
What it means
The name you asked git to push does not exist locally as a branch or a tag, and it cannot send what is not there. It happens in a brand-new repository with no commits yet, so main does not exist; or your local branch is master while you typed main; or it is simply a typo. git push -u origin HEAD pushes whatever branch you are actually standing on, under its real name, which clears the mismatched-name case in one step. If there are no commits at all, make one first — an empty repository has nothing to send.
The fix
git push -u origin HEAD- Printed by
- git
- Git
- 29
Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.
Reading an error message
- Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
- If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
- Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
- The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
- Before pasting a fix, check what it throws away. Some of these cannot be undone.
Common questions
Q. What does “error: src refspec main does not match any” mean?
The name you asked git to push does not exist locally as a branch or a tag, and it cannot send what is not there. It happens in a brand-new repository with no commits yet, so main does not exist; or your local branch is master while you typed main; or it is simply a typo. git push -u origin HEAD pushes whatever branch you are actually standing on, under its real name, which clears the mismatched-name case in one step. If there are no commits at all, make one first — an empty repository has nothing to send.
Q. How do I fix it?
git push -u origin HEAD — before running it, check the explanation above for what this command discards.
Q. Which tool prints this?
git. It sits under Git, and the message runs to 8 words.