How to fix "error: src refspec main does not match any"

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Git 2.43.0, November 29, 2026.

Git can’t push main because you don’t have a local branch called main. Check which branch you’re on:

git branch --show-current

Then use whichever fix matches:

git branch --show-current shows Cause Fix
Nothing, or git log says no commits You haven’t committed yet, or the commit failed git add . then git commit -m "First commit", then push
master Your branch is called master git branch -M main then git push -u origin main
Some other name You’re on another branch git push -u origin HEAD pushes the current branch
main, but you typed something else A typo in the push command Push the right name

We reproduced every row with Git 2.43.0. Git 2.43 still names a new repo’s first branch master unless you change the default, so the second row is the most common: the GitHub instructions say git push -u origin main, and the local branch is master.

What the error looks like

error: src refspec main does not match any
error: failed to push some refs to 'github.com:you/project.git'

src refspec main means “the local branch named main”. The push stops before anything is sent, so nothing on the remote changes.

Fix: no commit yet

A branch doesn’t exist until it has a commit. In our test, pushing right after git init gave this error:

git add .
git commit -m "First commit"
git branch -M main
git push -u origin main

If git commit says nothing to commit, your folder has no files Git is tracking yet, or they’re all in .gitignore.

Check that the commit really happened. On a machine where Git has never been set up, git commit stops with Author identity unknown and *** Please tell me who you are. In our test that left the repo with no commit, so the push that followed failed with the refspec error. Set your name and email, then commit again:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git commit -m "First commit"

Fix: your branch is master

git branch -M main
git push -u origin main

-M renames the current branch. This pushed successfully in our test. To stop it happening on future repos:

git config --global init.defaultBranch main

If the remote really uses master, push that instead: git push -u origin master.

Fix: push whatever branch you’re on

git push -u origin HEAD

HEAD means the current branch, so the name can’t be wrong. In our test this created the branch on the remote with the same name as the local one.

Confirm it worked

The push prints a line like * [new branch] main -> main, and git status says your branch is up to date with origin/main. If the push is now rejected because the remote has commits you don’t (for example a README made on GitHub), see refusing to merge unrelated histories.

FAQ

How do I rename master to main?

Run git branch -M main, then git push -u origin main. To make new repos start on main, run git config --global init.defaultBranch main.

Why does it say master does not match any?

Same error, other way round: your branch is called main and you pushed master. Push the branch you have, git push -u origin main, or check with git branch.

What is a refspec?

The part of a push or fetch command that says which branch goes where. In git push origin main, main is the refspec. Git couldn't find a local branch with that name.