Skip to content

/errors/git/src-refspec-does-not-match-any

error: src refspec main does not match any

verified onenvironmentlocal · linux 6.18.44-fc-v140 x64 · GNU bash 5.2.21 · git version 2.43.0updated
tool
Git
exit code
1
versions
Git 2.x
os
linux, macos, windows

error: src refspec main does not match any means git push origin main asked Git to push a local branch called main, and there is none. In a new repository the branch does not exist until the first commit; in older setups git init creates master instead. Commit first, or push the branch that does exist (git branch shows it), or rename it with git branch -M main.

Reproduce it

bash
git init -q --bare origin.git
git init -q -b main project && cd project
git remote add origin ../origin.git
echo "# demo" > README.md && git add README.md
git push -u origin main

Output · exit 1

error: src refspec main does not match any
error: failed to push some refs to '../origin.git'

git add staged the file, but there is no commit, so main is still an unborn branch.

Fix: commit, or push the branch you have

bash
git init -q --bare origin.git
git init -q -b master project && cd project
git remote add origin ../origin.git
echo "# demo" > README.md && git add README.md && git commit -qm "Initial commit"
git branch --show-current
git branch -M main
git push -q -u origin main
git ls-remote --heads origin

Output

master
d8d7df407e9ca7d6398cb520b28a9c3ef0422e08	refs/heads/main

Other refspec errors

MessageMeaning
src refspec X does not match anyNo local branch, tag or commit X
dst refspec X matches more than oneX is ambiguous on the remote (a branch and a tag with the same name)
failed to push some refs to ...Summary line printed after the actual reason

Sources