git 将新文件推送到裸仓库失败 : "error: src refspec master does not match any." Why?

标签 git push bare refspec

我正在尝试这个:

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/

相关文章:

git - 将一个 git 存储库的问题链接到另一个存储库的提交

php - array_push() 和 $array[] 之间的区别 =

javascript - 根据唯一ID确定是否推送或更新数组中的对象

iOS 应用程序无法接收报亭通知

windows - Git - 无法在 Windows 上推送到本地裸存储库

expo - 将 Expo 管理的工作流程转换为裸露的 React Native

git - 如何在不使用 reset 的情况下撤消 git 中的快进 merge

git - Pycharm,git : merge from master into branch

linux - 如何在我的家庭网络上访问 git 存储库?