Github:将上游分支导入分叉

编程入门 行业动态 更新时间:2024-10-27 00:35:27
本文介绍了Github:将上游分支导入分叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在github上有一个来自项目( upstream )的分支( origin )。现在上游项目添加了一个新分支,我想导入到我的分支中。我如何做到这一点?

我试着检查远程并在其上创建了一个分支,但是它以 git push 试图推送到上游:

git checkout upstream / branch git checkout -b branch

编辑 h3>

也许这并不明确,但我想将分支添加到我的本地存储库,以便我可以将它推送到 origin (我的叉)通过 git push 。因为上游软件仓库通常是只读的,所以你可以派它分发。

所以我基本上希望签出一个不存在的< origin ,其内容将被从上游。

解决方案

  • 确保您已将上游分支拉入您的本地回购:

    • 首先,确保您的工作树是干净的(提交/隐藏/恢复任何更改)
    • 然后, git fetch upstream 检索新的上游分支
  • 创建并切换到新的上游分支的本地版本( newbranch ):

    • git checkout -b newbranch upstream / newbranch
  • 当您准备将新分支推送到来源时:

    • git push -u origin newbranch
  • $ b

    -u 开关设置对指定远程的跟踪(在本例中, origin )

    I have a fork (origin) from a project (upstream) on github. Now the upstream project has added a new branch, I want to import into my fork. How do I do that?

    I tried checking out the remote and creating a branch on top of that, but that configures the branch the way that git push is trying to push to the upstream:

    git checkout upstream/branch git checkout -b branch

    edit

    Maybe that wasn't clear, but I want to add the branch to my local repository, so I can push it to origin (my fork) via git push. Because upstream repositories are usually read-only and you fork it to contribute.

    So I basically want to checkout a non-existent branch on origin whose contents will be pulled in from upstream.

    解决方案

  • Make sure you've pulled the new upstream branch into your local repo:

    • First, ensure your working tree is clean (commit/stash/revert any changes)
    • Then, git fetch upstream to retrieve the new upstream branch
  • Create and switch to a local version of the new upstream branch (newbranch):

    • git checkout -b newbranch upstream/newbranch
  • When you're ready to push the new branch to origin:

    • git push -u origin newbranch
  • The -u switch sets up tracking to the specified remote (in this example, origin)

    更多推荐

    Github:将上游分支导入分叉

    本文发布于:2023-07-04 17:26:18,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:分支   Github

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!