git: 错误: src refspec master 不匹配任何

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10568641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:40:37  来源:igfitidea点击:

git: error: src refspec master does not match any

git

提问by Alex Borsody

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

将 git 存储库克隆到目录“hggit”并使用以下命令设置远程源后

mbm:hggit my name$ git remote add origin [email protected]:"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 '[email protected]:"mystringhere"'

回答by VonC

If git statusdoes 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 status确实表明您确实有一个活动的 master 分支(因为毕竟您确实进行了第一次提交),请检查您在定义远程时是否犯了任何错字:请参阅“在新存储库上推送原始主错误”:

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

回答by Gal Bracha

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

使用 git branch -m 重命名本地存储库,使其与要推送到远程的名称相同

回答by savvadia

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

您需要确保本地和远程的分支名称相同。所以master在远程有分支是不够的。您在本地也需要这个分支。