我正在尝试这个:
mkdir ~/gitremote
cd ~/gitremote
git init --bare
我可以看到像这样的文件名
HEAD config hooks objects
branches description info refs
OK,然后在另一个目录下,
git clone trosky@localhost:/Users/trosky/gitremote
vi readme (add one line)
git add .
git commit -m "1st file"
git push origin master
然后报错:
$git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'trosy@localhost:/Users/trosky/gitremote'
我搜索了谷歌,它说这种错误是由于远程仓库上的空文件夹造成的。但是远程仓库不为空,并且我在本地提交了一个也不为空的文件。为什么还是提示出这个错误?
如何解决?谢谢。
最佳答案
尝试语法:
git push -u origin master
由于您要推送到一个空的仓库,因此您需要 explicitly push master
.
否则,default push.policy
being simple
, Git 会在你的远程仓库中寻找一个名为 master
的分支(因为你的远程裸仓库是空的,它还没有 master
分支)
当然,您不会在远程裸仓库中看到任何自述文件,因为它是裸仓库:没有工作树。
what's the difference between 'git clone /Users/trosky/gitremoe' and 'git clone 'trosy@localhost:/Users/trosky/gitremote'
一种是使用文件协议(protocol),也称为 local protocol , 其他 ssh protocol .您在这里不需要 ssh。
关于git 将新文件推送到裸仓库失败 : "error: src refspec master does not match any." Why?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41326402/