"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 —
Mainvsmain. - You're in the wrong folder, a different repository with different branches. Check with
pwdandgit 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
Next errors you might see
- Permission denied (publickey) — SSH key not set up.
- Updates were rejected — the GitHub repo already has commits.
- Refusing to merge unrelated histories — after pulling into a repo that started separately.
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
What Is ngrok? Share Your Localhost With the Internet
ngrok gives your local app a public HTTPS URL by tunnelling traffic to your machine. What it's for (webhooks, demos, mobile testing), how to use it, the request inspector, free vs paid limits, security cautions, and alternatives like Cloudflare Tunnel.
What Is curl? A Beginner's Guide With Practical Examples
curl is a command-line tool for making web requests, installed on almost every computer. The commands you'll actually use — GET, POST JSON, headers, authentication, following redirects, downloading files, seeing response headers — and how to read API docs that use it.