PlainError

error: src refspec main does not match any

Last checked 2026-11-11 · 3 fixes · reviewed answer

TL;DRThis Git error occurs when you try to push changes to a branch called 'main' that does not exist in your local repository yet. 'src refspec' is Git's internal term for the source reference (branch or commit) you are trying to send.

Most likely cause: No commits have been made yet, so the 'main' branch was never created

Try first: Check what branches exist locally (git branch)

Likely causes

  1. No commits have been made yet, so the 'main' branch was never createdmost likely
  2. The default branch is named 'master' instead of 'main'possible
  3. Typo in the branch name used in the push commandless likely

How to fix it

Safest first: SafeChanges settingsDangerous
  1. Check what branches exist locallySafe

    Run this to see if 'main' or another branch like 'master' is present.

    git branch
  2. Create an initial commit if none existChanges settings

    Add and commit at least one file so Git can create the branch.

    git add . && git commit -m "initial commit"
  3. Push using the correct existing branch nameChanges settings

    If your branch is called 'master', push that instead of 'main'.

    git push -u origin master

If that didn't fix it

Run 'git branch -a' to list all local and remote branches, then try pushing the branch that actually exists.

When to see a technician

Consult a developer or Git documentation if you are working inside a complex repository with multiple remotes or protected branches.

Quick answers

What does error: src refspec main does not match any mean?
This Git error occurs when you try to push changes to a branch called 'main' that does not exist in your local repository yet. 'src refspec' is Git's internal term for the source reference (branch or commit) you are trying to send.
What causes error: src refspec main does not match any?
No commits have been made yet, so the 'main' branch was never created. (most likely) The default branch is named 'master' instead of 'main'. (possible) Typo in the branch name used in the push command. (less likely)
How do I fix error: src refspec main does not match any?
Try these in order, safest first: 1. Check what branches exist locally. 2. Create an initial commit if none exist. 3. Push using the correct existing branch name.
What if that didn't fix it?
Run 'git branch -a' to list all local and remote branches, then try pushing the branch that actually exists.
When should I see a technician?
Consult a developer or Git documentation if you are working inside a complex repository with multiple remotes or protected branches.
Did this fix it? Report a problem

Related errors

All Coding errors →