【问题标题】:How can you clone a branch from the original GitHub project to your fork?如何从原始 GitHub 项目克隆一个分支到你的 fork?
【发布时间】:2017-11-24 19:32:26
【问题描述】:

我创建了一个 GitHub 项目。我想创建一个新分支,它是原始项目主分支的克隆(主分支从我上次分叉时开始有新的提交)。

我该怎么做?

【问题讨论】:

标签: git github


【解决方案1】:

从你的上游获取,结帐到那个分支,然后在你的 fork 上强制推送到那个分支。

git fetch upstream
git checkout <target branch>
git push -f origin <target branch>

免责声明:我尚未对此进行测试。

【讨论】:

  • 这假设 OP 已经配置了一个upstream 远程。
【解决方案2】:

首先你需要configure a remote for a the original repo

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
$ git fetch upstream

现在您可以将任何 git 命令与原始 repo 中的任何分支一起使用。

$ git checkout master
$ git pull upstream master

当然,您可以签出除 master 之外的任何其他分支。

$ git checkout my-radical-new-feature
$ git pull upstream master

通常我直接拉到我的本地 master 分支,如图所示,然后将本地 master 合并到我正在工作的其他分支中。

$ git checkout master
$ git pull upstream master
$ git checkout my-radical-new-feature
$ git merge master

详情请见the GitHub docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 2013-12-17
    • 2018-11-23
    • 2016-11-30
    • 2021-12-21
    • 2017-01-28
    • 2010-12-09
    • 2014-08-26
    相关资源
    最近更新 更多