Skip to main content

Git · 5 common causes

src refspec main does not match any

Updated

You asked Git to push a branch name that does not exist locally — usually because the repository has no commits yet.

The exact message

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

Paths, line numbers and stack frames differ on every machine, and the wording is tightened between versions. The part that identifies the problem is src refspec main does not match any.

How to fix it

Cause 1 of 5

The repository has no commits, so no branch exists yet.

Commit first: git add . then git commit -m "Initial commit", then push. A branch in Git is only a pointer to a commit, so with zero commits there is genuinely nothing named main to push.

Cause 2 of 5

Your branch is called master, not main.

git branch --show-current prints the real name. Either push that name, or rename it: git branch -M main followed by git push -u origin main.

Cause 3 of 5

Files are staged but never committed.

git status will say 'No commits yet'. Staging with git add does not create a commit — run git commit before pushing.

Cause 4 of 5

The branch name is misspelled.

git branch -a lists every local and remote branch. Push the exact name it shows; branch names are case-sensitive.

Cause 5 of 5

You are pushing a tag that does not exist locally.

The same error appears for git push origin v1.0 when there is no such tag. git tag lists them; create it with git tag -a v1.0 -m "Release 1.0" first.

Stopping it coming back

Set git config --global init.defaultBranch main so new repositories start with the name your host expects, and make the first commit before adding a remote.

src refspec main does not match any — common questions

What is a refspec?
The source:destination pair that tells Git what to push where. In git push origin main, main is shorthand for refs/heads/main:refs/heads/main. 'src refspec does not match any' means the left-hand side matched nothing locally.
Can I commit without files?
Yes, with git commit --allow-empty -m "Initial commit". That is a legitimate way to create the first commit so a branch exists, though committing your actual files is usually what you want.
Why does GitHub show main but my clone has master?
The default name changed across Git versions and hosts. The host renamed its default; your local Git config did not. git branch -M main renames the local branch, and setting init.defaultBranch stops the mismatch recurring.

Test the fix before you paste it back

Reproducing the failure in a scratch file is usually faster than editing the real one. AltF Code is a free in-browser editor with real syntax highlighting for HTML, CSS, JavaScript, TypeScript, Python, SQL and JSON, and it runs HTML, CSS and JavaScript live in a preview panel. No install and no sign-up.

Open the editor