git: error: src refspec master does not match any [duplicate]

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

This question already has an answer here:

After cloning git repository to directory "hggit" and setting the remote origin with

mbm:hggit my name$ git remote add origin git@code.getpantheon.com:"mystringhere" 

After editing files I committed the changes (while located in a sub-dir) with

mbm:handelgroup michaelmausler$ git commit -m "first commit" [master 5a29bc8] first commit  1 files changed, 2 insertions(+), 2 deletions(-) 

I then attempted to push file changes and received the following error

mbm:hggit myname$ git push origin master error: src refspec master does not match any. error: failed to push some refs to 'git@code.getpantheon.com:"mystringhere"' 

回答1:

If git status does indicate that you do have an active master branch (since you did make a first commit after all), check if you made any typo when defining your remote: see "Push origin master error on new repository":

git remote rm origin 

Then I recreated the origin, making sure the name of my origin was typed EXACTLY the same way my origin was spelled.

git remote add origin git@.... 

You can simplify with:

git remote set-url origin git@.... 

Then you can establish a tracking link between the local branch and the remote tracking branch:

git push -u origin master 

You can also push it to a different branch on origin:

git push -u origin master:anotherBranch 


回答2:

use git branch -m to rename your local repository to have the same name you want to push to the remote



回答3:

You need to make sure that the branch name is the same locally and remotely. So it's not enough to have master branch on remote. You also need this branch locally.



回答4:

Maybe your file have "\r" character



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