Git “src refspec main does not match any”: How to Fix It

The error src refspec main does not match any means Git cannot find a local source named main to push. The repository may not have a commit yet, or your current branch may have a different name such as master. Check the local repository first; changing the remote URL will not fix a missing local ref.

Practice Git workflows →

Check whether your repository has a commit

Start by checking the working tree, current local branch, and most recent commit:

git status
git branch --show-current
git log -1 --oneline

If git log reports that there are no commits, make the first commit before pushing. If it shows a commit but the current branch is not main, use the actual branch name or rename your local branch deliberately.

Fix 1: Create the first commit

A newly initialized repository has no branch commit for Git to push. Add the project files you intend to track, review what will be committed, and create a commit:

git status
git add .
git diff --staged
git commit -m "Initial commit"

Review git status and git diff --staged before committing; do not stage secrets, generated files, or other content that should not be in the repository. Once the commit exists, confirm the local branch name before pushing.

Fix 2: Push the branch you actually have

If the current branch is, for example, master, the source ref main does not exist locally. Push the current branch under its own name:

git push -u origin master

Replace master with the branch printed by git branch --show-current. Or, if you intend your local branch to be named main, rename it and push:

git branch -M main
git push -u origin main

Renaming the branch changes your local branch name; it does not rename an existing remote branch. Check your team’s default-branch convention before changing a branch that is already shared.

Confirm the remote if the correct branch still will not push

The refspec error itself points to the local source branch. If you have confirmed that the branch and commit exist but the push still fails, check whether origin is configured as expected:

git remote -v
git branch -vv

If there is no remote named origin, add the correct repository URL or use the configured remote name. An invalid remote, authentication problem, or server-side branch protection produces a different error after Git finds a valid local ref.

Common questions

Why does Git say main does not match any?

The push command names main as its local source, but Git cannot resolve that branch. Usually no commit exists yet, or the local branch has another name.

Is main the remote branch or my local branch in git push origin main?

In the simple form git push origin main, main is the local source ref Git tries to push. You can check it with git branch --list and git branch --show-current.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →