【问题标题】:Can git pull be used to update repository with an upstream可以使用 git pull 来更新带有上游的存储库吗
【发布时间】:2023-03-21 08:36:01
【问题描述】:

来自What is the difference between 'git pull' and 'git fetch'?

如果git pullgit fetch 后跟git merge 的组合,则git pull upstream master 可以用于获取并合并来自分叉存储库克隆中上游的更改.

【问题讨论】:

    标签: git github git-pull git-fetch


    【解决方案1】:

    正如@VonC 在他的answer 之一中所说-

    您必须将原始存储库(您分叉的存储库)添加为远程。

    来自GitHub fork man page

    克隆完成后,您的 repo 将有一个名为“origin”的远程指向您在 GitHub 上的 fork。
    不要让这个名字混淆你,这并不指向你分叉的原始仓库。为了帮助您跟踪该 repo,我们将添加另一个名为“upstream”的远程:

    $ cd github-services
    $ git remote add upstream git://github.com/pjhyett/github-services.git
    $ git fetch upstream
    
    # then: (like "git pull" which is fetch + merge)
    $ git merge upstream/master master
    
    # or, better, replay your local work on top of the fetched branch
    # like a "git pull --rebase"
    $ git rebase upstream/master
    

    从远程分支获取后,您仍然需要合并提交。

    这里你可以做的是替换

    $ git fetch upstream
    

    $ git pull upstream master
    

    因为git pull 本质上是git fetch + git merge,正如你所说。

    【讨论】:

      【解决方案2】:

      简答NO。您必须将上游存储库添加为另一个远程。当然,您可以将其命名为 upstream。然后运行git pull upstream master

      你可以像这样添加遥控器:

      git remote add upstream <url-of-upstream-repo>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-28
        • 1970-01-01
        • 2011-05-18
        • 2011-04-15
        • 1970-01-01
        • 2010-11-01
        相关资源
        最近更新 更多