Git 错误:src refspec master 不匹配任何错误:无法推送一些引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12452042/
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
Git error: src refspec master does not match any error: failed to push some refs
提问by user1676428
I am trying to add a file to my repository on BitBucket and I am having trouble.
我正在尝试将文件添加到我在 BitBucket 上的存储库中,但遇到了问题。
I am using GIT and this is what I type in
我正在使用 GIT,这就是我输入的内容
$ 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)
然后我输入这个(这是 BitBucket 告诉我输入的)
$ git remote add origin https://[email protected]/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://[email protected]/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.
有人可以帮我吗?我已经尝试了从 git commit 到 rm -rf * 的所有方法,但我根本无法进行任何操作。
回答by VonC
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
- 当 repo 已初始化 (
git init lis4368/assignments
) 时, - 但从未提交过
Ie, if you don't have added and committed at least once, there won't be a local master
branch to push to.
即,如果您没有至少添加和提交一次,则不会有本地master
分支可以推送到。
Try git commit -m "first commit"
and then try git push -u origin master
again.
尝试git commit -m "first commit"
,然后再试git push -u origin master
一次。
See "Why do I need to explicitly push a new branch?" for more.
请参阅“为什么我需要明确推送一个新分支?”了解更多信息。
回答by Brice Lin
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.
它不承认你有一个 master 分支,但我找到了一种绕过它的方法。我发现 master 分支没有什么特别之处,您可以创建另一个分支并将其称为 master 分支,这就是我所做的。
To create a master branch:
创建主分支:
git checkout -b master
And you can work off of that.
你可以解决这个问题。