You created the repository, added the remote, ran the push, and Git answered with this:
error: src refspec main does not match any
error: failed to push some refs to 'git@github.com:you/your-repo.git'The message is about your machine, not the server. git push origin main asks Git to send a local branch named main, and Git is saying no such branch exists here. Four things cause that, and the first two account for most of it. All output below came from Git 2.55.
Find the Cause in One Command
git branch --show-current && git log --oneline -1Read the result:
- Nothing printed at all. You have no commits yet. Go to Fix 1.
- A branch name that isn’t the one you pushed (
masterwhen you pushedmain). Go to Fix 2. - The right branch and a commit. You mistyped the branch name in the push. Go to Fix 3.
git status answers the same question in more words: “No commits yet” is the phrase to look for.
Fix 1: Commit Something First
A branch in Git points at a commit, so a branch with no commits doesn’t exist yet, even though git branch --show-current prints a name. This is the usual case right after git init: files staged, nothing committed.
git status --porcelain # 'A file.txt' means staged, not committed
git add .
git commit -m "First commit"
git push origin mainStaging is not committing. git add alone leaves you with the same error, because there’s still no commit for the branch to point at.
Fix 2: Push the Branch You Actually Have
Git init created master for years, and many machines still do. GitHub names the default branch main, so the branch you have and the branch you push differ.
git branch --show-current
# master
git push origin main
# error: src refspec main does not match anyPush the branch you have:
git push origin masterOr rename it to match the remote, which is usually what you want:
git branch -M main
git push -u origin mainSet the default for new repositories so this stops happening:
git config --global init.defaultBranch main-M renames the branch and overwrites any existing one of that name. -u records the upstream, so later pushes are a bare git push.
Fix 3: Check the Branch Name for Typos
The refspec is echoed back to you verbatim, so the error names the branch Git looked for:
error: src refspec mian does not match anyThat is mian, not main. Compare the name in the error with git branch --show-current, character by character. The same applies to a branch you deleted or never created locally.
Fix 4: Push the Current Branch Without Naming It
When you keep hitting the wrong name, let Git supply it:
git push -u origin HEADHEAD means the branch you’re on, so the name can’t disagree with reality. After the first -u push, git push alone does the right thing.
Why the Second Line Appears
The error always arrives in a pair:
error: src refspec main does not match any
error: failed to push some refs to 'git@github.com:you/your-repo.git'The second line is a consequence, not a separate problem. Git had nothing to send, so the push failed. If the second line instead mentions permissions or authentication, you have a different problem: see Fix Permission Denied (publickey).
Verify
git push -u origin main
git branch -vv # the branch now tracks origin/main
git ls-remote --heads origingit ls-remote asks the server what branches it has. Seeing your branch there means the push landed.
Related Content
- Fix Permission Denied (publickey) in SSH and GitHub covers the authentication error that stops a push for a different reason.
- Fix GitHub Push Declined Email Privacy Error covers the third error people hit on a first push to GitHub.
References
- git-push(1), for refspec syntax and what
HEADmeans in a push. - Git Book: Remote Branches, for how local branches map to remote ones.

Comments #