【问题标题】:How to add an existing project to GitHub using the command line? [duplicate]如何使用命令行将现有项目添加到 GitHub? [复制]
【发布时间】:2020-04-19 11:59:34
【问题描述】:
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/08S/Error.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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

【问题讨论】:

标签: git


【解决方案1】:

您在创建远程存储库时选择了 GitHub 上的选项,以使用现有历史记录(自述文件)创建它。您想替换该历史记录,因此强制推动它:

git push --force
# git push -f

或者,如果您还没有设置上游:

git push --force --set-upstream origin HEAD
# git push -uf origin HEAD

为避免未来现有的存储库出现这种情况,请在 GitHub 上选择将新存储库留空的选项。

【讨论】:

    【解决方案2】:

    似乎远程存储库有一些本地存储库中没有的更改。所以,你有两个选择。

    1. 通过git pull命令将远程repo中的更改集成到本地repo中,然后将本地更改推送到远程repo。

    2. 通过git push --force 命令将本地更改推送到远程存储库,从而丢弃远程存储库中的更改。

    【讨论】:

      猜你喜欢
      • 2015-02-11
      • 1970-01-01
      • 2015-12-16
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 2015-03-17
      相关资源
      最近更新 更多