error: src refspec main does not match any

git push origin main refused with a cryptic refspec error. Almost always you have no commit on that name yet — or the branch is called something else.

What the error actually means

src refspec main does not match any means Git looked for a local ref named main to send, and found nothing. It is not (yet) a permissions or auth problem — those look like Permission denied (publickey) or HTTP 401/403.

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

Cause table

Symptom alongside the errorLikely causeFix
git log → fatal: bad default revision / your current branch does not have any commitsEmpty repo — no first commit, so no branch tip existsgit add … then git commit -m "…" , then push
git branch shows master (or trunk) onlyDefault branch name mismatchPush master, or git branch -M main then git push -u origin main
git branch shows main but push still failsTypo in the command (mian), or pushing a tag/ref that does not existCopy the exact name from git branch --show-current
Detached HEAD, no branch line with *You are not on a branchSee detached HEAD; create/switch a branch first
Works locally, CI failsCI checks out a shallow clone or different default branchAlign git push ref with what the workflow checks out; fetch depth

Empty repository (most common for brand-new projects)

git status
# No commits yet…

git add .
git commit -m "Initial commit"
git branch -M main          # optional: rename current branch to main
git remote add origin [email protected]:you/repo.git   # if not already set
git push -u origin main

Until the first commit exists, main is only a wish — Git has no object to point the name at, so the refspec matches nothing.

Branch is called master (or something else)

git branch -a
# * master

# Option A — push the name you have
git push -u origin master

# Option B — rename locally, then push main
git branch -M main
git push -u origin main

On GitHub/GitLab/Bitbucket, set the repository default branch to match what you push, or the "default branch" banner will keep pointing at an empty main.

Inspect before you force anything

Do not reach for --force to fix a refspec error; force does not create a missing local branch. Force-with-lease belongs to rewriting a branch that already exists on the remote — see push rejected (non-fast-forward).

Related git headaches

After the first push you may hit non-fast-forward, divergent branches, unrelated histories, or not a git repository if you are in the wrong folder. Comparing two commit messages or file copies: text diff. Checking a tarball matches: hash generator.

Related

git push rejected (non-fast-forward) · git divergent branches · detached HEAD · fatal: not a git repository · unrelated histories

Questions

What does src refspec main does not match any mean?

Git cannot find a local ref named main to push. Usually there are no commits yet, or your branch is called master (or another name).

How do I fix it on a new repo?

git add, git commit, optionally git branch -M main, then git push -u origin main.

Why does git branch show nothing?

With zero commits, some Git versions show no branches. Make the first commit and the branch tip appears.

Should I use master or main?

Either works if the remote default matches. Many hosts default to main now; rename with git branch -M main before the first push if you want that name.

Is this the same as Permission denied (publickey)?

No. Auth failures happen after Git has a valid local ref to send. Fix the refspec first, then SSH/HTTPS auth if needed.

Can force-push fix a refspec error?

No. --force does not create a missing local branch. Commit (or rename) first.

Published .

Try it

Related guides

Newest guides