我在Github上创建了一个新的存储库,现在只有Readme.md文件。
我有一个新创建的RoR项目,我想将其推送到此存储库。以下是我在终端中给出的执行此命令的命令,以及我收到的错误。
git remote add origin https://github.com/aniruddhabarapatre/learn-rails.git
然后我输入了我的用户名和密码
git push -u origin master
错误--
To https://github.com/aniruddhabarapatre/learn-rails.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/aniruddhabarapatre/learn-rails.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这是我第一次将我的代码推送到Github存储库,我对这些错误感到迷惑。我搜索了这里提出的其他几个问题,但它们都没有第一次出现问题。
发布于 2014-09-05 09:37:50
如果这是您第一次推送,那么您可能不关心遥控器上的历史记录。然后你可以做一个“强制推送”来跳过git所做的检查,以防止你在远程覆盖任何现有的或不同的工作。使用时要特别小心!
只需更改
git push **-u** origin master
把它改成这样!
git push -f origin master
发布于 2015-01-07 13:32:53
使用以下命令发出强制推流:
git push -f origin master
发布于 2014-01-06 05:57:23
假设您通过github提供的接口添加了Readme.md文件,那么自述文件还不在本地文件夹中。因此,当您尝试推送到远程repo时,您会得到一个错误,因为您的本地repo缺少readme文件-可以说它“落后于时代”。因此,按照错误消息中的建议,首先尝试"git pull“。这将从远程存储库中提取自述文件,并将其与本地目录合并。在此之后,您在推送到远程存储库时应该不会有任何问题(您发布的命令在我看来是有效的)。
https://stackoverflow.com/questions/20939648
复制相似问题