skip to Main Content

Whenever i execute the command git push -u origin main i get the response from the terminal error: src refspec main does not match any
error: failed to push some refs to ‘https://github.com/Po etc etc,
does anyone know a solution?

I tried to relink the remote origin which the terminal tells me exists, ive ran git status which shows me all the currently staged files waiting to be committed. From there i ran git commit and then ran git push -u origin main which worked but im confused why it didnt work beforehand?

2

Answers


  1. See this reasons of your error

    Your stage area need to be cleared before pushing to remote repository, and that is why you need to commit before pushing.
    This is what I found searching on Internet:

    This error mainly occurs when you attempt to push your local changes to GitHub while the local repository (repo) has not yet been updated with any changes made in the remote repo. So Git is trying to tell you to update the local repo with the current changes in the remote before pushing your own changes.

    Login or Signup to reply.
  2. It could be that the main branch didn’t exist yet in the online repository, so that’s why you received that error message. By committing your changes prior to pushing, you were able to create the main branch in the online repository and then push it. Another possibility is that there was a mistake in the branch name or some kind of permissions problem which prevented you from pushing your changes. If the issue continues, you can attempt to remove both the local and remote main branches and create them again. If that doesn’t work, you can always reach out to GitHub support for assistance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search