【问题标题】:How to create Github repository from a site that's already live [duplicate]如何从已经存在的站点创建 Github 存储库 [重复]
【发布时间】:2019-08-22 01:02:34
【问题描述】:

我在使用 Git 时遇到了一些问题。

我已经在 Digital Ocean 液滴上托管了一个实时站点。我想将我的代码推送到 github 存储库,然后在本地进行所有开发。我会将本地代码推送到 github,然后通过从 github 拉取来更新实时站点。

但是,我在起步时遇到了一些麻烦。

我已经创建了 repo,我在项目上做了一个快速的git init。我已经添加了文件,进行了提交,然后添加了 repo。但是,当我运行 git push 时,我得到了这个:

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 github master

所以,我跑了git push --set-upstream github master。它给了我这个错误:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/WordsofDefiance/davidaccomazzo.com.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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

谁能帮我创建这个对 repo 的初始提交?我想我错过了一些超级基本的东西。

编辑:我最终在推送时使用了--force,它起作用了。谢谢。

【问题讨论】:

    标签: git github web-deployment


    【解决方案1】:

    要回答有关上游错误的第一个问题,这是因为要在没有任何其他参数的情况下运行 git push,您需要设置默认远程分支。这是为了让 git 知道将您的代码发送到哪里。通过将上游设置为github master,您实际上是在告诉 git 在运行git push 时运行git push github master。关于它的工作原理有更详细的答案here

    至于您的第二个问题,silmari 可能是正确的,您的远程存储库(在 GitHub 上)实际上并不为空。如果您在最初在 GitHub 上设置存储库时选择添加许可证文件(例如 MIT)或 .gitignore 文件,则可能会发生这种情况。在这种情况下,GitHub 为您创建了一个提交,而您在本地没有该提交,这就是发生冲突的地方。

    所以我首先要做的是查看您的 GitHub 存储库的提交历史记录,看看那里是否有您在本地没有的任何提交。因为您已经在本地进行了提交,所以您可能必须对远程分支执行 git rebase 以“清理”您的本地历史记录,并能够推送(无需诉诸强制推送)。

    再说一次,这在很大程度上是我的猜测。希望对你有帮助。

    【讨论】:

    • 我最终做了一个git push --force 并设置了上游主机并且它工作了。看起来我现在可以提交了,没问题。感谢您的帮助。
    【解决方案2】:

    嗯,这是一个愚蠢的答案,但是,您使用的存储库似乎不存在,是您创建的吗?

    如果是这样并且它不公开,它真的是空的吗? git push --force 可能会有一些用处。

    【讨论】:

    • 它实际上是一个私人仓库。这有什么改变吗?
    • 那会产生不同的错误。
    猜你喜欢
    • 2020-10-11
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 2020-11-22
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    相关资源
    最近更新 更多