Message 'src refspec master does not match any' when pushing commits in Git
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The Git error src refspec master does not match any means Git cannot find a local reference named master to push. In practice, that usually comes down to one of three things: the branch is actually named main, the branch has no commits yet, or the push command names the wrong local ref.
What the Error Actually Means
In a command such as git push origin master, the word master refers to a local branch, tag, or other ref that Git should send to the remote. If that local ref does not exist, Git has nothing to push and prints the error.
That is why this is a local-state problem first, not a remote authentication problem.
Check the Current Branch Name
The first thing to verify is your current branch:
If the repository uses main instead of master, then this command is wrong:
and this is the correct one:
Modern hosting platforms often initialize repositories with main, so this is the most common cause today.
Make Sure the Branch Has a Commit
Another common case is a brand-new repository with files added but no commit yet. Git does not have a real branch tip to push until at least one commit exists.
Check whether the branch has a commit:
If Git reports that there are no commits yet, create one:
If your branch is actually named master, replace main with master. The important point is that the branch must exist as a committed ref before it can be pushed.
A Safer Push Command
If you are unsure about the local branch name, pushing HEAD is often clearer:
This tells Git to push the branch currently checked out, instead of hard-coding master or main. It is especially useful in scripts or when working across repositories with different default branch names.
When You Need to Rename the Branch
Sometimes the local branch is master, but the remote repository expects main, or vice versa. In that case, rename the branch explicitly:
-M forces the rename. This is common when standardizing old repositories onto newer branch naming conventions.
Distinguish Local and Remote Problems
It helps to separate a few different Git errors:
- '
src refspec ... does not match anymeans the local ref is missing' - authentication or permission errors mean the remote rejected you
- non-fast-forward errors mean the remote branch exists but your history is behind
Knowing that distinction saves time. If the error mentions src refspec, do not start with tokens, SSH keys, or branch protections. Start with local branches and commits.
Common Pitfalls
- Typing
masterout of habit when the branch is reallymain. - Trying to push before creating the first commit.
- Assuming the remote default branch name automatically creates a matching local branch.
- Hard-coding branch names in scripts when
HEADwould be safer. - Chasing remote-permission fixes for what is actually a missing local ref.
Summary
- The error means Git cannot find the local ref named in your push command.
- Check whether your branch is
main,master, or something else. - Make sure the branch has at least one commit before pushing.
- '
git push -u origin HEADis a safe way to push the current branch.' - Treat this as a local-branch problem first, not a remote-auth problem.

