src refspec does not match any
This error occurs when you attempt to push a branch that does not exist in your local repository or has no commits yet.
Usually happens because:
- ☑ No commits have been made in the repository yet
- ☑ Local branch name differs from remote name (master vs main)
- ☑ Typo in the source branch name parameter string
🔍 Quick Checklist:
What is src refspec does not match any?
This error is thrown by the Git client when the source branch (refspec) you specify in a push command (e.g. 'git push origin main') cannot be found on your local system. In Git, a branch pointer is not created until you make at least one commit. Common causes include trying to push to 'main' when your active branch is named 'master', typos in branch names, or trying to push a newly initialized repository before committing any files.
Common Causes
- No commits in repository: The repository is empty (newly initialized) and has no commits, so the default branch has not been created yet.
- Branch name mismatch: Trying to push 'main' but the local branch is named 'master' (or vice versa).
- Branch name spelling typo: A typo in the branch name parameter during the push command.
| Cause | Frequency |
|---|---|
| No commits yet in newly initialized repository | ⭐⭐⭐⭐⭐ |
| Local branch name mismatch (master vs main) | ⭐⭐⭐⭐ |
| Typo in local branch name string | ⭐⭐⭐ |
Common Mistakes
- Trying to push to `origin main` when local branch is named `master`, which yields a refspec mismatch because Git cannot map the non-existent local `main` pointer.
- Forgetting to stage files using `git add` before attempting a commit, leaving the workspace empty.
How to Fix
Git Operations & Verification
Ensure your repository has at least one commit before attempting to push branches to a remote server.
# 1. Create a dummy file
$ echo "# My Project" > README.md
# 2. Stage and commit files
$ git add README.md
$ git commit -m "first commit"
# 3. Push now succeeds
$ git push -u origin masterPlatform Specific Fixes
Check currently checked out active branch names on Linux.
git branch --show-currentBest Practices
- Run `git status` frequently to confirm branch states and staging queues.
- Configure your global Git profile to use modern standard default branch configurations.
Frequently Asked Questions (FAQ)
Q: What is a refspec?
A refspec is a format Git uses to map local branches (source) to remote branches (destination). It is written as 'local_branch:remote_branch'.
Q: Why does 'main' not exist in a new repository?
Git does not create the default branch pointer until the first commit is created. An empty repository has no branches.
Q: How do I rename 'master' to 'main'?
Run 'git branch -M main' to force-rename your active branch to 'main'.
Q: How do I check what branches exist locally?
Run 'git branch' to list all local branches. The one marked with an asterisk (*) is your active branch.