error: src refspec main does not match any
Filed under Deployment failures
Git cannot find a local branch named main — usually because the project has never been committed (no commit, no branch), or your branch is actually named master.
Fastest route
Give your AI this prompt
Copy it, replace the bracketed part with your error, and send it.
Preview the prompt
When I try to push my project I get: error: src refspec main does not match any error: failed to push some refs to '[my repository URL]' Here is what these commands show in my project folder: [paste the output of git status and git branch]. I work in [name your tool or "a terminal"], and this is [my first push ever for this project / a project I have pushed before]. Please: 1) tell me from the git status and git branch output which case I am in — no commits yet, a branch named something other than main, or the wrong folder, 2) give me the exact commands for my case, in order, explaining each in one plain sentence, 3) if a first commit is needed, include the git config commands in case Git does not know my name and email yet, 4) tell me what a successful push output looks like so I can confirm it worked. Constraints: do not suggest deleting the .git folder or re-initializing the repository, do not suggest force pushing, and do not rename anything until you have explained which branch I actually have.
Fix it yourself
Follow the repair
- Ask Git what state you are actually in. Run these two commands in the project's folder and read them before changing anything:
git status tells you whether there are uncommitted files and whether any commit exists at all ("No commits yet" says it outright). git branch lists your real branches, with a star next to the one you are on. If the list is empty, you have the no-commit case — go to step 2. If it lists master or another name, skip to step 3.git status git branch - If there are no commits, make the first one. This is the fix in the overwhelming majority of cases:
The commit creates the branch, and the push now has something to send. If git commit complains that it does not know who you are, set your identity once with git config --global user.email "[email protected]" and git config --global user.name "Your Name", then commit again.git add . git commit -m "Initial commit" git push -u origin main - If your branch is named master, align the names. You have two honest options. Push what you have:
Or rename your branch to main — the name GitHub and nearly all instructions now expect — and push that:git push -u origin master
Renaming is safe: it renames the label, not your work, and your commit history comes along untouched.git branch -M main git push -u origin main - Check for the quiet impostors. If commits exist and the branch name looks right, verify you are standing in the project you think you are:
git log --oneline -1shows your latest commit (an error here means this folder's repository has no commits, whatever the other folder has), andgit remote -vshows where origin points. People regularly commit in the copy the AI tool made and push from the copy they downloaded, and Git quite correctly finds no main in the second one. - In an AI builder, use its Git panel for the first commit. If your project lives in Replit, Bolt, or a similar tool, the first commit often has to happen inside the tool: look for its Git or Version Control panel, stage the files, and commit there — some tools call this creating a checkpoint or snapshot. Once one commit exists in the tool's repository, pushing works. If the tool connected GitHub for you, also confirm in that panel which branch it created; several default to names other than main.
- Remember the -u for next time. The
-uin git push -u origin main links your local branch to the remote one. After that first successful push, plaingit pushis all you need for the rest of the project's life — this error is a first-push rite of passage, not a recurring problem.
Why this happensOptional explanation
When you run git push origin main, you are asking Git to take your local branch called main and copy it to the remote. "Src refspec main does not match any" is Git's stiff way of saying: I looked, and there is no branch by that name here. Branches in Git are not folders that exist in advance — a branch is created by your first commit. Until something is committed, the project is in a strange pre-branch state where tools may even display "main" as the intended name while no actual main exists.
This error is practically the official welcome sign of a first push. AI builders make it more likely: the tool generates a full project, connects it to GitHub, and offers a push — but a commit was never made, or the initial commit exists only inside the tool's own environment while you are pushing from your own terminal. The second classic is the master/main mismatch: older setups and some tools still create master as the default branch, while GitHub and most instructions now assume main, so the push names a branch that was never yours.
- No commits yet: the project was generated or initialized but never committed — nothing exists to push.
- Branch named master: your work is all there, under the old default name, while the push asks for main.
- A typo or wrong name: the push names a branch that differs from your actual one by a word or a letter.
- Wrong folder: you are running push in a directory that is a different repository — or no repository — than the project you committed.
Quick answers
Why does Git say main does not exist when my tool shows main as the branch?
Because a branch is created by a commit, not by initializing the project. Until the first commit exists, Git may display main as the intended branch name while no actual branch exists — so the push goes looking for main and finds nothing. One commit (git add . then git commit) creates it.
My branch is called master. Should I rename it or just push master?
Neither is wrong. Master was the old default name; main is the current one, and GitHub expects main. Push master as-is if you like, or rename with git branch -M main — renaming changes the label only, and your history comes along untouched. Most people rename once and match every tutorial from then on.
I have definitely committed. Why does it still fail?
Only if this folder's repository genuinely has commits and a matching branch — people regularly commit in one copy of a project and push from another (the AI tool's copy versus a downloaded copy). Run git log --oneline -1 and git branch in the folder you are pushing from; an empty result means that copy has no commits, whatever the other copy holds.