我尝试使用GitHub文档中的说明创建GitHub存储库,但与其在本地创建README
,我使用README
选项初始化了我的GitHub存储库。在尝试推送后,我遇到了这个我不完全理解的错误:
kirby:cs61as_SCIP_schython \**user**$ git push origin master
https://github.com/chris-marie/cs61as_SICP_schython.git
! [rejected]
master -> master (fetch first) error: failed to push some refs to
'https://github.com/chris-marie/cs61as_SICP_schython.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.
我也无法拉取存储库,于是我尝试手动下载、添加和提交我曾经虚拟创建的README
文件,然后再次尝试推送,结果出现了一个新错误:
kirby:cs61as_SCIP_schython \**user**$ git push origin master
https://github.com/chris-marie/cs61as_SICP_schython.git
! [rejected]
master -> master (non-fast-forward) error: failed to push some refs to
'https://github.com/chris-marie/cs61as_SICP_schython.git' hint:
Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git
pull') hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这让我有了四个问题:
1. 为什么在GitHub上用一个README
初始化远程仓库,然后尝试将GitHub仓库与之前已有的本地仓库连接,不能成功?
当我尝试修复此错误时,为什么无法拉取(pull)代码?
即使我手动从GitHub将
README
添加到我的本地仓库后,为什么仍然无法推送(push)并初始化与GitHub远程仓库的连接?如何创建一个带有已初始化的
README
的GitHub仓库,并将其连接到本地repo而不导致这些错误?
git clone
还是git init
然后再使用git remote add ...
? - Leighgit init
命令。在尝试将本地仓库连接到远程仓库之前,我还正确地添加了文件并进行了第一次提交。 - Chris Marie