Fix 'src refspec main does not match any'
git push fails with 'src refspec main does not match any' — what does that mean?
If you’re seeing this error
error: src refspec main does not match anyerror: failed to push some refs to '<url>'error: src refspec master does not match anyYou’re in the right place — the fix is below.
Short answer
You asked Git to push a branch that does not exist locally. Either you have made no commits yet — a repository with zero commits has no branches at all — or your branch is called master and you are pushing main. Run git log --oneline and git branch to see which, then commit or rename.
git branch # what branches exist?
git commit -m "Initial commit"
git branch -M main
git push -u origin main
The usual sequence: commit first, then name the branch, then push
Does this match your situation?
- 'error: src refspec main does not match any'
- 'error: src refspec master does not match any'
- It happens on the very first push of a brand-new repository.
- git branch prints nothing at all.
- You are pushing a tag or branch whose name you typed slightly wrong.
Step-by-step fix
Check whether you have any commits
A branch is a pointer to a commit, so a repository with no commits has no branches — even though git init said it was on main. This is the cause the large majority of the time, and git branch printing nothing is the tell.
step 1git log --oneline git branch git status'fatal: your current branch does not have any commits yet' confirms it outright.
Stage and commit something
The first commit creates the branch. If git status shows nothing to commit because the folder is empty, an empty commit is a perfectly valid way to start a repository.
step 2git add . git commit -m "Initial commit" # nothing to add yet: git commit --allow-empty -m "Initial commit"Check the name you are actually on
Git's historical default was master and it is still what older installations create; GitHub has used main since 2020. Pushing the name the host expects while sitting on the other one produces this error exactly.
step 3git branch --show-current git branch -M main # rename current branch to main git config --global init.defaultBranch mainPush and set the upstream
-u records the relationship, so from then on plain git push and git pull know where to go without arguments.
step 4git push -u origin mainCheck for a typo if the branch does exist
The same message appears for a mistyped branch or tag name. Git is not being cryptic here — 'refspec' just means the thing you named on the left of the colon, and it could not resolve it.
step 5git branch -a git tag -l git push origin feature/login # the exact name, spelled as git branch prints it
Why this works
A refspec is the source:destination pair a push is built from, and 'src' is the left-hand side — the thing you are asking Git to send. Git resolves that name locally before it opens a connection, and if nothing in your repository answers to it, there is nothing to transmit and it stops. The confusing part is that git init reports you are on main immediately: what it created is an unborn branch, a HEAD pointing at a name that has no commit behind it yet. Nothing exists to push until the first commit gives that name something to point at, which is why the fix is almost always to commit rather than to change anything about the remote.
If that didn’t work
- Confirm the remote exists at all: git remote -v.
- Pushing a tag needs the tag to exist locally — check git tag -l first.
- Branch names are case-sensitive to Git even where your filesystem is not.
- In a fresh clone of an empty repository, make a commit before any push will work.
How to stop it happening again
- Set init.defaultBranch main once, so local and hosted branch names always agree.
- Commit before creating the remote — GitHub's own instructions assume you already have one.
- Use git push -u on the first push so later pushes need no arguments.
- Copy branch names from git branch output rather than typing them.
Commands used in this guide
git pushUpload your commits to the remote repository.
git branchList, create, rename and delete branches.
git commitRecord everything currently staged as a permanent snapshot.
git remoteManage the named URLs your repository syncs with.
git logBrowse commit history with as much or as little detail as you want.
Still stuck?
Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
What does 'src refspec main does not match any' mean?
Git could not find anything locally called main to push. Either the repository has no commits yet — in which case no branch exists regardless of what git init printed — or your branch has a different name, usually master.
Why does this happen on a brand-new repository?
Because branches are pointers to commits, and until you make the first commit there is no commit for main to point at. git branch printing nothing confirms it. Commit, then push.
How do I rename master to main?
git branch -M main renames the current branch, and -M forces it even if main already exists. Then git push -u origin main. If master was already pushed, delete it on the host afterwards with git push origin --delete master.
What is a refspec in Git?
The source:destination pair that tells Git what to transfer and where to put it — main:main in a normal push. 'src refspec' is the left-hand side, the local thing being sent, which is why this error is always about something missing locally rather than on the server.
Can I push an empty repository?
Not as-is, but git commit --allow-empty -m "Initial commit" creates a commit with no changes, which gives the branch something to point at. That is a common way to establish main on a new remote before any real work exists.
Related rescue guides
Git says my branch has no upstream branch — what do I set and why?
A new local branch has no counterpart on the server, so plain git push and git pull do not know where to go. git push -u origin <branch> creates it and records the link in one step. To link an existing remote branch without pushing, use git branch --set-upstream-to=origin/<branch>.
Read the fix →Always fixablegit remote add origin fails with 'remote origin already exists' — what do I do?
This repository already has a remote called origin, usually because it was cloned or because you ran the same setup instructions twice. Check where it points with git remote -v. If it is wrong, change it with git remote set-url origin <url> rather than adding a second one.
Read the fix →Always fixableMy push was rejected — 'Updates were rejected because the remote contains work that you do not have'. What now?
Someone pushed commits you don't have yet, so your push would erase them. Git is protecting you. Fetch and integrate their work first with git pull --rebase, then push again. Never reach for --force here unless you genuinely intend to delete what's on the server.
Read the fix →Always fixableHow do I rename a Git branch?
git branch -m <new-name> renames the branch you're on. Renaming on the server takes two more steps, because Git has no rename operation for remote branches — you push the new name and delete the old one.
Read the fix →