【问题标题】:git: How to fetch from a remote branch and merge into local branch?git:如何从远程分支获取并合并到本地分支?
【发布时间】:2012-01-02 00:44:03
【问题描述】:

我是分叉的

导致

  • github.com/MYACCOUNT/ma​​ntisbt

从我克隆它的地方并将分支(我感兴趣)签出到我的本地机器。

我的问题是我想从远程存储库 (mantisbt/mantisbt) 获取最新的分支 (master-1.2.x) 并将其合并到我的本地存储库的同一分支下。

这会导致类似

  • git fetch remote-repo-branch
  • git 合并 remote-repo-branch/local-branch

这是怎么做到的?

更新:

内容是通过

获取的
  • git fetch 上游 master-1.2.x

并合并到当前签出的分支

  • git 合并 origin/master-1.2.x

【问题讨论】:

标签: git github


【解决方案1】:

Github 在他们的 "fork a repo" help documentation 中有一个完全这样的例子。

git remote add upstream git://github.com/mantisbt/mantisbt 
// Assigns the original repo to a remote called "upstream"
git fetch upstream

【讨论】:

  • 我试过了(在问这里之前)但是当你克隆时,只有 master 分支是由“fetch”和“merge”“创建”和“更新”的。当远程仓库被分叉时,分支不受影响并保持在修订版上。
  • 您只需要指定要拉取的上游分支的名称即可。为此,还有其他一些关于 SO 的问题。 stackoverflow.com/questions/67699/…stackoverflow.com/questions/1709177/…。基本上git fetch upstream other-branch
【解决方案2】:

什么对我不起作用(git 版本 1.7.9.5 并使用 HTTPS 协议):

最初我将“foobar.git”从“他们的帐户”分叉到“我的帐户”:

their_account/foobar.git => my_account/foobar.git

感兴趣的分支是“baz”

我在“baz”上工作并做出了承诺,他们也这样做了。我想将他们的提交与我的合并。正如上面 ptomli 建议的那样,我做到了:

$ git checkout baz
$ git fetch https://github.com/their_account/foobar.git baz
Username for 'https://github.com': my_account
Password for 'https://my_account@github.com': 
remote: Counting objects: 189, done.
remote: Compressing objects: 100% (109/109), done.
remote: Total 189 (delta 92), reused 151 (delta 76)
Receiving objects: 100% (189/189), 107.77 KiB, done.
Resolving deltas: 100% (92/92), done.
From https://github.com/their_account/foobar
 * branch            baz -> FETCH_HEAD

我没有看到的步骤是:

$ git merge FETCH_HEAD

两个分支合并了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-06
    • 2018-12-20
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多