Home › Git

error: src refspec main does not match any — how to fix

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

Quick fix: Check your branch name with git branch. If it says master, push that (git push origin master) or rename it with git branch -M main. If there are no commits, commit first.

What it means

The main in git push origin main is a local branch name, and Git can't find a local branch with that name.

Cause 1: no commits yet

A brand-new repository has no branch until the first commit.

git add .
git commit -m "Initial commit"
git push -u origin main

If git commit says "nothing to commit", you have no files staged. Check git status.

Cause 2: your branch is called master (or something else)

git branch

If it shows * master, either push that:

git push -u origin master

or rename it to main (what GitHub expects by default):

git branch -M main
git push -u origin main

To make new repositories start with main: git config --global init.defaultBranch main.

Cause 3: a typo or wrong case

Branch names are case-sensitive: Main and main are different branches. Copy the exact name from git branch.

Last updated 2026-10-27.