git 错误:src refspec master 不匹配任何
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21264738/
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
error: src refspec master does not match any
提问by special0ne
I have tried to follow the solutions suggested in thispost but it didnt work and I am still getting: src refspec master does not match any.
我已经尝试遵循这篇文章中建议的解决方案,但它没有用,我仍然得到:src refspec master 不匹配任何。
Here is what I did: Followed thissolution
这是我所做的:遵循此解决方案
// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.
When doing:
做的时候:
$ git push origin HEAD:master
b40ffdf..a0d1423 HEAD -> master // looks promising
// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master does not match any.
More information:
更多信息:
$ git branch
* origin
$ git show-ref
refs/heads/origin
refs/remotes/devstage/master
refs/remotes/origin/HEAD
refs/remotes/origin/devstage
refs/remotes/origin/master
refs/remotes/origin/origin
So I am definitely missing refs/heads/master but dont know how to create it.
所以我肯定缺少 refs/heads/master 但不知道如何创建它。
Thanks
谢谢
采纳答案by apprenticeDev
From git branch
it appears that somehow your local branch name is "origin".
从git branch
某种程度上看来,您的本地分支名称是“起源”。
You can rename the branch with -mv
flag, like this:
您可以使用-mv
标志重命名分支,如下所示:
git branch -mv origin master
git branch -mv origin master
After this git branch
should show master
:-)
在这之后git branch
应该显示master
:-)
Just to make sure the name is indeed the only thing that went astray, you can run git log
and look at the last few commits - and compare them to the last few commits on bitbucket website.
为了确保名称确实是唯一误入歧途的东西,您可以运行git log
并查看最后几次提交 - 并将它们与 bitbucket 网站上的最后几次提交进行比较。
回答by nithinreddy
This should help you
这应该可以帮助你
git init
git add .
git commit -m 'Initial Commit'
git push -u origin master
回答by iwayankit
i have same problem, to solve it, follow these steps
我有同样的问题,要解决它,请按照下列步骤操作
git init
git add .
git commit -m 'message'
git push -u origin master
after this, if you still having that error, follow these steps again
在此之后,如果您仍然遇到该错误,请再次执行这些步骤
git add .
git commit -m 'message'
git push -u origin master
that worked for me and Hope it will help anyone
这对我有用,希望它能帮助任何人
回答by Adrien Parrochia
Try to do :
试着做 :
git push origin HEAD:master
回答by arslan ahmed mir
I was having the SAME ERROR AGAIN AND AGAIN.
我一次又一次地犯同样的错误。
I added files in local repository and Trying the command
我在本地存储库中添加了文件并尝试命令
"git push origin master"
“git push origin master”
Showed Same Error
显示相同的错误
ALL I WAS MISSING I DID NOT COMMIT .
我缺少的只是我没有提交。
" git commit -m 'message' "
“ git commit -m '消息'”
After Runnig this it worked
在Runnig之后它起作用了
回答by Saikat
Try following command:
尝试以下命令:
git push origin HEAD:master
Git threw the below error when I tried simply git push
. So clearly this is because Git matches the local and remote branch while pushing commits. This is the push.default
behavior, you can find out more details here.
当我简单地尝试时,Git 抛出了以下错误git push
。很明显,这是因为 Git 在推送提交时匹配本地和远程分支。这是push.default
行为,您可以在此处找到更多详细信息。
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:<Branch_Name>
To push to the branch of the same name on the remote, use
git push origin <Branch_Name>
To choose either option permanently, see push.default in 'git help config'.
回答by Springer F
By just adding an empty commit will fix issue by using
通过添加一个空提交将通过使用解决问题
$ git commit -m "empty commit" --allow-empty
$ git push
// above make empty commit without edit then push
// 上面做空提交而不编辑然后推送
回答by TomCheung
The error demo:
错误演示:
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git add --all
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git status
On branch dev
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
new file: photo.jpg
new file: style.css
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git push origin dev
error: src refspec dev does not match any.
error: failed to push some refs to '[email protected]:yourRepo.git'
You maybe not to do $ git commit -m "discription"
.
你也许不做$ git commit -m "discription"
。
Solution:
解决方案:
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git commit -m "discription"
[dev (root-commit) 0950617] discription
3 files changed, 148 insertions(+)
create mode 100644 index.html
create mode 100644 photo.jpg
create mode 100644 style.css
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git push origin dev
To [email protected]:Tom007Cheung/Rookie-s-Resume.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to '[email protected]:yourRepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
回答by Sonu
Run the command git show-ref
, the result refs/heads/YOURBRANCHNAME
If your branch is not there, then you need to switch the branch by
运行命令git show-ref
,结果refs/heads/YOURBRANCHNAME
如果你的分支不存在,那么你需要切换分支
git checkout -b "YOURBRANCHNAME"
git show-ref
, will now show your branch reference.
git show-ref
, 现在将显示您的分支参考。
Now you can do the operations on your branch.
现在您可以在您的分支上进行操作。
回答by Tomasz Wójcik
This error can typically occur when you have a typo in the branch name.
当分支名称中有拼写错误时,通常会发生此错误。
For example you're on the branch adminstration
and you want to invoke:
git push origin administration
.
例如,您在分支上adminstration
并且想要调用:
git push origin administration
。
Notice that you're on the branch without second i
letter: admin(i)stration
, that's why git prevents you from pushing to a different branch!
请注意,您在没有第二个i
字母的分支上:admin(i)stration
,这就是为什么 git 阻止您推送到不同的分支!