src refspec does not match any

Git OperationsPush ErrorCommonLast updated: June 29, 2026Tested on:Git CLI v2.44GitHub APIJune 2026

This error occurs when you attempt to push a branch that does not exist in your local repository or has no commits yet.

src refspec does not match any Quick Fix⏱️ Est. Fix Time: 1 minute

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.
CauseFrequency
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

1Create a commit first: Stage files using 'git add' and run 'git commit' to initialize the active branch.
2Rename branch to main: Rename the active branch to match the destination branch using 'git branch -M main'.
3Check active branch name: Run 'git branch' or 'git status' to verify the exact spelling of your current local branch.

Git Operations & Verification

Ensure your repository has at least one commit before attempting to push branches to a remote server.

Creating First Commit Example
# 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 master

Platform Specific Fixes

Check currently checked out active branch names on Linux.

Linux Config
git branch --show-current

Best 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.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error