Skip to content
  1. LuzineDebug
  2. Git & GitHub
  3. error: src refspec main does not match any
Git & GitHub Beginner ≈ 3 min to fix

Fix "error: src refspec main does not match any" on git push

Error message
error: src refspec main does not match any
  • error: src refspec master does not match any
  • error: src refspec main does not match any error: failed to push some refs to 'https://github.com/user/repo.git'
  • error: src refspec feature/login does not match any
  • error: src refspec v1.0 matches more than one
In short

The branch you want to push does not exist locally: either you have not made any commit yet, or your branch is called master, not main. Make a first commit, rename the branch with git branch -M main, then run git push -u origin main.

Be the first to confirm this fix

What this error means

In git push origin main, main is a "refspec": Git looks for a local reference (branch, tag) with that name to send. "src" means the source side, that is your local repository. If no reference matches, there is nothing to push. The most common case: after git init, the branch only really exists after the first commit; before that, git branch shows nothing. Another frequent case: Git creates master by default if init.defaultBranch is not set, while GitHub suggests git push -u origin main. The "matches more than one" variant means a branch and a tag share the same name.

Common causes

  1. No commit: git init and git add were run, but git commit was forgotten or failed (user.name / user.email not configured, no file added).
  2. master branch instead of main (or the other way round): the local name does not match the one in the command.
  3. Typo or case mismatch in the branch name, for example feature/Login instead of feature/login.
  4. Branch that only exists on the remote: you see it on GitHub but never created or checked it out locally.

Step-by-step fix

  1. List local branches and commits

    If git log answers "does not have any commits yet", you must commit first. Otherwise, note the exact name of the current branch.

    bash
    git status
    git branch --show-current
    git branch -a
    git log --oneline -n 3
  2. Make the first commit

    Set your identity if Git asks for it ("Please tell me who you are"), add the files, then commit.

    bash
    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"
    git add .
    git commit -m "Initial commit"
  3. Rename the branch or push the right name

    Rename the local branch to match the remote, or simply push the real name (git push -u origin master).

    bash
    git branch -M main
    git push -u origin main
  4. Push the current branch without typing its name

    HEAD means the branch you are on: the command avoids any typo and creates the branch with the same name on the remote.

    bash
    git push -u origin HEAD
  5. Branch only on the remote

    Fetch it and create the local branch that tracks it before working on it and pushing it.

    bash
    git fetch origin
    git switch feature/login
  6. "matches more than one" variant

    A branch and a tag share the same name: give the full reference type in the command.

    bash
    git push origin refs/heads/v1.0
    git push origin refs/tags/v1.0

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Set the default branch name once and for all: git config --global init.defaultBranch main.
  • Use git push -u origin HEAD for the first push of a branch: you cannot get the name wrong.
  • Avoid giving a branch and a tag the same name (prefix tags with v, branches with feature/).

Frequently asked questions

Why does git branch show nothing after git init?

A branch is a pointer to a commit. Until a commit exists, the branch is only a pending name: it appears after the first git commit.

Should I use main or master?

Both work. GitHub, GitLab and Bitbucket use main by default for new repositories; what matters is using the same name locally and on the remote.

Does git branch -M delete anything?

No, it renames the current branch and keeps all its commits. -M forces the rename if a local main branch already exists: check with git branch first.

Useful tools for this error

More Git & GitHub errors

All Git & GitHub errors →