Git “src refspec does not match any”: push a branch that exists
Check that the branch exists locally and that you have at least one commit before pushing.
Git cannot find a local ref matching the branch name you pushed. Confirm the branch name with git branch, make sure the repository has at least one commit, then push the correct name.
Try these fixes in order
List the actual local branch names
Run git branch --show-current to see the checked-out branch name and git branch to list all local branches. Compare these names character-for-character with the refspec in your push command.
git branch --show-currentgit branchMake sure the repository has a commit
Run git log --oneline -3. If Git reports that the repository has no commits, the branch does not exist yet as a ref. Stage your files and create the first commit before pushing.
git add -Agit commit -m "Initial commit"Push the correct name or rename the branch
If the branch exists under another name, either push that exact name with git push origin <actual-name> or rename the branch deliberately with git branch -m <old> <new> and then push.
git push origin <branch-name>git branch -m <old-name> <new-name>Set the upstream for future pushes
After pushing the right ref once, set the upstream with git push -u origin <branch> so future bare git push commands target the intended remote branch.
git push -u origin <branch-name>Interpret what you see
The error names the branch you typed in the push command
What it suggests: Git could not expand the refspec because no local branch, tag, or commit expression matches that name.
Next check: Run git branch --show-current and git branch -a to list the actual local branch names.
git log shows no commits in the repository
What it suggests: A fresh git init repository has no refs at all until the first commit, so any branch name in a push fails this way.
Next check: Run git log --oneline -3; if it reports no commits, make an initial commit first.
git branch lists a branch close to, but not exactly, the pushed name
What it suggests: The branch exists but under a different name, commonly master versus main, or a typo in the push command.
Next check: Compare git branch output with the exact refspec you pushed and correct the name.
Why this happens
- The local repository has no commits yet, so the branch name does not exist as a ref.
- The local branch is named differently than the refspec, for example master locally versus main in the push command.
Still not working?
Do not force-push or delete remote branches to make this message go away; the error means the local ref was not found, so there is nothing to force. If the repository truly has no commits, the fix is to create the first commit, not to adjust push flags.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.