我最近创建了一个空的github仓库,我陷入了重复错误消息的循环中,这些消息似乎与git提供的建议消息无关。
我添加了一个文件:
git add filename
git commit -m "commit message"
git push origin master
这给了我以下信息:
Updates were rejected because the tip of your current branch is behind.
its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
所以我试试:
fatal: refusing to merge unrelated histories
然后我尝试:
git push -f
这给了我:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
但是,如果我尝试我得到:
error: failed to push some refs to 'https://github.com/JonathanBechtel/cdc-
dashboard.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
如果我尝试git stash -u
,我告诉我没有要藏匿的文件。
是否有人对此重复的错误消息循环有解释?
答案 0 :(得分:1)
使用此:
git pull origin master --allow-unrelated-histories
然后你的git push
应该成功:
git push origin master
正如this SO article所讨论的那样,您可能会在第一次拉动期间收到无关的历史错误,因为您的本地分支显示为新的并且与远程分支的历史没有任何共同之处。
答案 1 :(得分:1)
您的local master
分支落后于remote master
分支。推送之前更新本地。
$ git pull origin master # update local master
$ git push origin master # push the changes