【问题标题】:How do I turn a git clone into a fork and then push to heroku from the fork?如何将 git clone 变成 fork,然后从 fork 推送到 heroku?
【发布时间】:2014-09-08 17:45:15
【问题描述】:

我克隆了一个存储库,认为我不需要更改任何内容。现在我想改变一些东西。

我在 github 上分叉了代码,但现在我不确定下一步该做什么。我不想进行更改,然后不小心提交到我从中克隆的存储库。

【问题讨论】:

    标签: git heroku github fork clone


    【解决方案1】:

    您的本地git 存储库根据“远程”确定推送/拉取的位置。现在,您的本地存储库有两个远程,origin(现在指向您克隆的 Github 存储库)和 heroku(指向 Heroku 存储库)。

    您将源分叉到 Github 上的新存储库;假设旧的是https://github.com/bob/website.git,而你的叉子是https://github.com/pixelfairy/website.git

    如果你这样做

    git remote -v
    

    你应该看到类似的东西

    origin  https://github.com/bob/website.git (fetch)
    origin  https://github.com/bob/website.git (push)
    ...
    

    我们可以更改此设置,以便 origin 指向您的分叉。做

    git remote set-url origin https://github.com/pixelfairy/website.git
    

    现在git remote -v 应该输出

    origin  https://github.com/pixelfairy/website.git (fetch)
    origin  https://github.com/pixelfairy/website.git (push)
    ...
    

    您现在可以像以前一样使用 pushpull,它将使用您的 fork 而不是最初克隆的存储库。

    【讨论】:

    • 现在试试这个。谢谢!!
    【解决方案2】:

    只需添加到@tbekolay 答案,如果需要,您仍然可以从克隆的原始分支中获取/拉取,以便跟上那里的更改。通过添加仍然指向原始遥控器(在本例中为 bob)的“上游”(或其他命名的)遥控器来做到这一点。

    git remote add upstream https://github.com/bob/website.git
    

    然后你可以不时从那里拉取更新你的代码:

    git pull upstream <branch name>
    

    如果您想更改新的远程使用方式:

    git remote set-url upstream <new url>
    

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 2021-07-13
      • 2020-09-16
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      相关资源
      最近更新 更多