
Fix ‘src refspec main does not match any’
Git says src refspec main does not match any when no local branch has that name. Check for no commits, master versus main, typos and empty clones.

Tap a step number as you finish it.
The message error: src refspec main does not match any means Git could not resolve the source name in your push command to something it can push. The remote is not the problem.
The most common causes are a branch with no commits yet, a branch name that does not match, or a typo. The same error appears when you push a tag that does not exist.
You can tell which one applies within seconds using this guide. It rests on reproductions with Git 2.43.0 and on Git's own source and manual, checked on October 21, 2026.
The short answer
- Run git branch –show-current to see which branch you are on. With a detached HEAD it prints nothing at all.
- Run git log –oneline -1 to see whether the branch has a commit.
- Commit your staged files if the branch has no commit yet.
- Push the real branch name, or rename the branch with git branch -M main, if the names differ.
- Run git push -u origin main once main exists locally and has a commit.
Did these steps work for you?
Pushing to a different remote name also works, for example git push -u origin HEAD:refs/heads/main, but renaming usually leaves a tidier setup.
The message repeats what you typed. A capital M, as in error: src refspec Master does not match any, fails for the same reason, since capital letters matter in branch names.
What the message means
A refspec has a source and a destination. In git push origin main, the source is the local branch main, and src in src refspec means that source side.
Git looks for a local ref with that name, finds none and stops.
The line that follows, error: failed to push some refs to, is the generic summary Git prints for every rejection. Our guide to git push rejected: every cause explains why it never names the reason.
One message, several shapes
| What you ran | The message says | What it means |
|---|---|---|
| git push origin main | src refspec main | There is no local branch called main, or it has no commits |
| git push | src refspec refs/heads/main | The current branch has no commits |
| git push origin HEAD | src refspec HEAD | The current branch has no commits |
| git push origin v1.0 | src refspec v1.0 | No local tag has that name |
| git push origin Master | src refspec Master | Capital letters count in branch names |
Diagnose it in 30 seconds
git branch --show-current
git branch --list
git log --oneline -1
git status -sb
git branch –show-current
Prints the name of the branch you are on. In the test it printed master where the push said main. In a detached HEAD state it prints nothing.
git branch –list
Lists every local branch. A name that is missing from the list is your cause.
git log –oneline -1
Prints your latest commit. A repository without commits has none to show.
git status -sb
On a fresh repository it prints ## No commits yet on main, with any staged files listed below it.
Cause 1: the repository has no commits yet
A new repository has a branch name but no commit, and the branch ref exists only once the first commit does. Running git add stages files but does not commit them.
In the test, git status showed No commits yet on main with a file staged, and the push failed.
error: src refspec main does not match any
error: failed to push some refs to 'https://example.com/team/app.git'
- Run git status -sb and confirm it says No commits yet.
- Run git add . to stage your files, or name the files you want.
- Create the first commit with git commit -m "Initial commit".
- Run git push -u origin main to push and set the upstream.
Did these steps work for you?
The manual explains that -u (–set-upstream) records the upstream for each branch that is current or pushed without error. That is why later plain git push and git pull commands know where to go.
Cause 2: the branch is called master
Git's own default for a new repository is master unless you configure it. Tutorials and hosting sites often assume main.
In the test, git init with no configuration printed a hint saying it used master and that the default name is subject to change.
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
Renaming
Run git branch -M main to rename the current branch. Git's manual says -M must be used to force the rename when a branch with the new name already exists.
Keeping master
Run git push -u origin master if you are happy to keep master on the remote.
Mapping names
Run git push -u origin HEAD:refs/heads/main to send your current branch to a remote branch called main. Your local branch keeps its name.
The test confirmed the rename: after git branch -M main, git branch –show-current printed main, and the push no longer failed with this message.
If the remote already has a branch called master as its default, pushing a new main creates a second branch instead of updating the first. Decide which name the remote should use before you push.
Cause 3: a typo or a different branch name
Capital letters matter in branch names. In the test, pushing Master produced error: src refspec Master does not match any. Pushing develop failed the same way, because no local branch had that name.
- Run git branch –list and copy the exact name from it.
- Push that name, for example git push -u origin the-exact-name.
The same message appears when you are inside a different repository than you think. Run git status in the folder first, and confirm it is the project you meant.
Cause 4: you cloned an empty repository
Cloning a remote that has no commits works, but it leaves you in the same state as a new repository. Git warns you at clone time, and the first push then fails with this message.
warning: You appear to have cloned an empty repository.
error: src refspec main does not match any
error: failed to push some refs to 'https://example.com/team/app.git'
A plain git push in that state spells out the full ref: error: src refspec refs/heads/main does not match any. Pushing with git push origin HEAD reports src refspec HEAD does not match any.
All three mean there is no commit to push.
Cause 5: you pushed a tag that does not exist
A tag name works as a push source too. In the test, git push origin v1.0 failed with error: src refspec v1.0 does not match any, because no tag had that name.
- Run git tag to list the tags your repository has.
- Create the tag on your current commit with git tag v1.0.
- Run git push origin v1.0 to send it. The test printed [new tag] v1.0 -> v1.0.
Did these steps work for you?
A tag needs a commit to point at. With no commits in the repository, git tag v1.0 stopped with fatal: Failed to resolve 'HEAD' as a valid ref. Make the first commit before you tag.
Cause 6: you cannot make the first commit
Two common problems stop people creating the commit the push needs. Git refuses to commit until it knows who you are, and it refuses to commit when nothing is staged.
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Set both values, then commit again. With nothing staged, such as in an empty folder, Git replies nothing to commit (create/copy files and use "git add" to track).
Add files first, and check that your .gitignore is not excluding all of them. In the test, a * rule in .gitignore left git status showing No commits yet with nothing staged.
If the repository genuinely needs a commit but has no files to commit, git commit –allow-empty -m "Initial commit" creates an empty commit. In the test, it let git push -u origin main succeed straight away.
If you meant to publish project files, check your staging area and .gitignore instead.
How Git reads the source name
The source can be a branch, a tag or a full ref. In the test, git push origin refs/heads/main:refs/heads/main worked, and git push origin master:main worked too.
Here is the mapping form in one line.
git push -u origin master:main
That sends your local master to a remote branch called main. It does not rename your local branch. It only maps the source to a differently named destination.
Git explained why the short form works in a related message. When the source is a ref under refs/heads or refs/tags, it adds the matching prefix to the destination name on the remote side.
Stop it happening again
Choose a default branch name one time and each new repository begins on main. Both options below come from Git's documentation.
Global setting
Run git config –global init.defaultBranch main to set the initial branch name for every repository you create afterwards.
If your repositories already exist, the setting does not change them. Rename those with git branch -M main.
What you may see next
Fixing this message often reveals the next one, because the remote may hold work your local repository does not.
Remote already has commits
A repository created with a README gives the remote a first commit. Your push is then rejected with (fetch first). Our guide to git push rejected: every cause shows how to merge it with –allow-unrelated-histories.
No upstream
A plain git push on a branch without an upstream prints fatal: The current branch has no upstream branch and shows the git push –set-upstream command to run.
Success
A working push prints the branch pair, such as main -> main, and, with -u, branch 'main' set up to track 'origin/main'.
Frequently asked questions
Why does git push -u origin main fail straight after git init?
Because the repository has no commit yet. Make a first commit, then push.
What is a refspec?
It is the pair of names in a push, written source:destination. In git push origin main, the source is your local main, and the destination defaults to the same name.
Can an empty commit fix it?
Yes. git commit –allow-empty -m "Initial commit" creates a commit with no files, which gives the branch something to push.
Can I push my master branch to a remote branch called main?
Yes. Run git push origin master:main. When the source is a branch, Git adds the refs/heads prefix to the destination for you.
Does the branch name matter to Git?
Not technically. It is a convention, and a platform may use a particular name as its default branch. Pick one name and keep it consistent.
Is the remote broken?
No. The message appears because a local branch is missing, so check your own repository first.
A quick checklist
From circuittimes.com/cloud-dev/fix-src-refspec-main-does-not-match-any/
Was this guide helpful?
What went wrong?
Read nextComparison 13 min readGit Merge vs Rebase: When to Use Each, With Real ExamplesGit merge, rebase, fast-forward and squash compared with real command output, conflicts, force pushing and pull settings.
Comparison 11 min readJest vs Vitest: Which Test Runner to Use in 2026
Comparison 10 min readPlaywright vs Cypress: Which Testing Tool in 2026
Comparison 12 min readGitHub vs GitLab vs Bitbucket: Which to Choose in 2026
The briefing, without the noise.
The stories that matter in technology, every weekday morning.
Free. Unsubscribe in one click.







