1

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?

  • Does this answer your question? [Git: Message 'src refspec master does not match any' when pushing commits in Git](https://stackoverflow.com/questions/4181861/git-message-src-refspec-master-does-not-match-any-when-pushing-commits-in-git) – Eng_Farghly Sep 30 '21 at 21:47

2 Answers2

4

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

phd
  • 69,888
  • 11
  • 97
  • 133
-1

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
Héctor Valverde Pareja
  • 1,115
  • 1
  • 13
  • 32
  • This does not address the question, which was about a main/master branch name mismatch, not about the URL for origin. – joanis Nov 13 '21 at 22:25