"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
"Python Is Not Recognized as an Internal or External Command": How to Fix It
On Windows, "'python' is not recognized as an internal or external command, operable program or batch file" (or "pip is not recognized") means Windows can't find Python on your PATH. How to check whether Python is installed, use the py launcher, add Python to PATH, turn off the Microsoft Store alias, and fix pip.
The grep Command: Search Files and Logs Like a Pro
grep searches text for lines that match a pattern — in files, whole folders, or the output of another command. The examples you'll actually use: case-insensitive search, recursive search, line numbers, context around matches, counting, excluding folders, regex, and grepping logs, plus ripgrep.