Blog
2 min read

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

Git can't push a branch called main because it doesn't exist locally — usually because there are no commits yet or the branch is called master. How to check which it is and fix it in one or two commands.

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

You ran git push origin main (often your very first push), and Git says it has no main to push.

"src refspec" is Git's way of saying "the source branch you named". There is no local branch called main. There are two common reasons.

Reason 1: you haven't committed anything yet

A branch doesn't really exist until it has at least one commit. After git init and git add, but before git commit, there's nothing to push.

Check:

git log

If you see fatal: your current branch 'main' does not have any commits yet, that's it. Commit first:

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

If git commit complains about your name and email, set them once:

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

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

Older Git versions and some setups name the first branch master. GitHub's instructions say main.

Check:

git branch
* master

Either push what you have:

git push -u origin master

or rename it to main first (most people do this, to match GitHub):

git branch -M main
git push -u origin main

To make every new repository start with main:

git config --global init.defaultBranch main

Other, rarer causes

  • A typo in the branch name — git push origin mian.
  • Case differences — Main vs main.
  • You're in the wrong folder, a different repository with different branches. Check with pwd and git status. (fatal: not a git repository)

The sequence that always works for a new project

git init
git add .
git commit -m "First commit"
git branch -M main
git remote add origin git@github.com:you/my-app.git
git push -u origin main

(git remote add origin)

Next errors you might see


EasySpawn sets up your project's repository and remote for you, and Claude Code can sort out Git errors like this in one message. See how it works or join the waitlist.

Related: git remote add origin · Git and GitHub for Beginners · Git Branches Explained · Git Push Rejected

Keep reading