ProjectStack
git

error: src refspec does not match any

Git can't find the branch you're trying to push because it doesn't exist locally. Usually the local branch name doesn't match what you typed in the push command.

Common causes

  • The branch is named 'main' locally but you typed 'master' (or vice versa)
  • You haven't made any commits yet, so the branch doesn't exist as a ref
  • There's a typo in the branch name you specified
  • You're pushing before making the first commit on a new repo

How to fix it

  1. Check what local branches exist: git branch
  2. Push using the correct branch name: git push origin main
  3. If no commits yet, make the first commit before pushing: git add . && git commit -m 'Initial commit'
  4. Rename your branch if needed: git branch -m old-name new-name

Example

error: src refspec main does not match any error: failed to push some refs to 'origin'

Running git push origin main on a new repo that has commits on 'master' instead of 'main'

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.