/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
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 mainOutput · 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
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 originOutput
master d8d7df407e9ca7d6398cb520b28a9c3ef0422e08 refs/heads/main
Other refspec errors
| Message | Meaning |
|---|---|
| src refspec X does not match any | No local branch, tag or commit X |
| dst refspec X matches more than one | X 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
Related pages
errors · gitfatal: couldn't find remote refgit fetch, pull or clone names a branch or tag the remote does not have. Check the name with git ls-remote, fix the typo or a main/master mismatch, then retry.errors · giterror: failed to push some refs (rejected, fetch first)git push is rejected with failed to push some refs when the remote branch has commits you do not have. Pull or fetch and rebase first, then push again safely.errors · gitfatal: The current branch has no upstream branchgit push fails with this on a new local branch that has no upstream. Push once with git push -u origin BRANCH, or set push.autoSetupRemote to true (Git 2.37+).cheat sheets · gitGit cheat sheet: everyday commandsGit cheat sheet: setup, stage and commit, branches with switch, history, undo with restore, reset and revert, stash, remotes, tags and the reflog on one page.