Git error: src refspec master does not match any error: failed to push some refs [duplicate]

百般思念 提交于 2019-12-20 08:35:16

问题


I am trying to add a file to my repository on BitBucket and I am having trouble.

I am using GIT and this is what I type in

$ cd lis4368/assignments
$ git remote
$ git remote -v
$ git remote rm origin

and then I type this in (this is what BitBucket tells me to enter)

$ git remote add origin https://cpb09e@bitbucket.org/cpb09e/cpb09e.git
$ git push -u origin master

And I keep getting this error message:

error: src refspec master does not match any.
error: failed to push some refs to 'https://cpb09e@bitbucket.org/cpb09e/cpb09e.git'

Can someone pleas help me out? I have tried everything from git commit to rm -rf * and I cannot get anything to work at all.


回答1:


One classic root cause for this message is:

  • when the repo has been initialized (git init lis4368/assignments),
  • but no commit has ever been made

Ie, if you don't have added and committed at least once, there won't be a local master branch to push to.

Try git commit -m "first commit" and then try git push -u origin master again.

See "Why do I need to explicitly push a new branch?" for more.




回答2:


It doesn't recognize that you have a master branch, but I found a way to get around it. I found out that there's nothing special about a master branch, you can just create another branch and call it master branch and that's what I did.

To create a master branch:

git checkout -b master

And you can work off of that.



来源:https://stackoverflow.com/questions/12452042/git-error-src-refspec-master-does-not-match-any-error-failed-to-push-some-refs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!