I have a local branch named master and its upstream is set to origin/main
But whenever I push to remote repo using git push -u origin main
it shows error:
error: src refspec main does not match any
error: failed to push some refs to
But it works fine when I use git push -u origin HEAD:main
So what’s the Problem in here?
1
git push origin main
means “push local branch main
” and you don’t have local branch main
, you have master
. After the first git push -u origin master:main
you should push using git push origin
or even bare git push
. Or continue pushing using git push origin master:main
1
This error appears when the branch you are trying to push your local repository does not exist.
“error: src refspec main does not match any” – Means, no branch called “main” was found in the source.
So, Make a branch like this:
git push --set-upstream origin [branch name]
In this case:
git push --set-upstream origin master
This will create a branch called “master” and will push changes to that branch.
Try the following commands. It would change the origin
git remote add origin https://github.com/username/repo.git
- then Verify remote URL is correct:
git remote -v
- then Push to repo
git push origin master
1