更新 Github 上分叉存储库的多个分支

发布于 2024-10-05 18:54:17 字数 350 浏览 3 评论 0原文

我有一个分叉的 github 存储库(称为 repo-O,称为我的分叉 repo-F),其中包含大约 8 个分支。其他贡献者已在 repo-O 的多个分支上对 repo-O 进行了多次(100 次)提交。我现在想将这些更改放入我的分叉存储库 (repo-F) 中。我无法使用 fork 队列,因为有大约 3000 个提交需要挑选,我更愿意从命令行执行此操作。

所以..我已经克隆了我的存储库,添加了repo-O作为远程(上游)并获取了更改,然后合并了origin/upstream...然后推回了repo-F。

这似乎已将更改应用于主分支,但未应用于任何其他分支......

我如何重复上述过程以便更新“所有”分支?

谢谢

I have a forked github repository (call it repo-O and call my fork repo-F) which contains about 8 branches. Several (100s) commits have been made to repo-O from other contributors, and on multiple branches of repo-O. I would now like to pull these changes into my forked repo (repo-F). I cant use the fork queue as there are about 3000 commits to pick through, and I would much rather do this from the command line.

So.. I have cloned my repo, added repo-O as a remote (upstream) and fetched the changes, followed by merge origin/upstream... then a push back to repo-F.

This appears to have applied the changes to the master branch, but not to any other branch....

How can I repeat the above process so that 'all' the branches are updated?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄意 2024-10-12 18:54:17

您想要完成的是“对于 repo-o 上的每个远程分支,创建指向 repo-o 分支的相同分支(如果我没有),或者从 repo 上同一分支上的任何内容提取本地分支上的信息- o,最后将所有这些分支推送到我的 repo-f”。

假设您的遥控器确实名为 repo-orepo-f,我会在 bash 中使用类似的内容:

for repo_o_branch in \
    $(git branch -a|grep repo-o|perl -nle's,^\s*repo\-o/,,;print $_';
do
    (                                                              \
       ( git checkout $repo_o_branch                               \
         && git pull --rebase repo-o $repo_o_branch)               \
       || ( git checkout -b $repo_o_branch repo-o/$repo_o_branch ) \
    ) && git push repo-f $repo_o_branch;
done

对于所有“repo o 分支”(由 gitbranch -a 显示为“repo-o/branchname”,不带“空格和‘repo-o/’”部分),

  • 尝试检查分支并且在其中执行git pull --rebase repo-obranchname
  • 或者,如果git checkout失败(因为您没有该分支) :检出一个以 repo-o 的分支名称命名的新分支,并将其指向 repo-o 的分支名称。
  • 如果以上两者中的任何一个成功,请将新创建或更新的分支名称推送到您的 repo-f。

调味;最好在新创建的 repo-f git 克隆上尝试,并添加远程 repo-o,以防万一出现问题;)

What you want to accomplish is "for each remote branch on repo-o, create the same branch pointing to repo-o's branch if I don't have it or pull information on the local branch from whatever is on the same branch on repo-o, and at the end push all these branches to my repo-f".

Assuming your remotes are really named repo-o and repo-f, I'd play with something like, in bash:

for repo_o_branch in \
    $(git branch -a|grep repo-o|perl -nle's,^\s*repo\-o/,,;print $_';
do
    (                                                              \
       ( git checkout $repo_o_branch                               \
         && git pull --rebase repo-o $repo_o_branch)               \
       || ( git checkout -b $repo_o_branch repo-o/$repo_o_branch ) \
    ) && git push repo-f $repo_o_branch;
done

For all "repo o branches" (shown by git branch -a as " repo-o/branchname", without the "spaces and 'repo-o/'" part of it),

  • try checking out the branch and doing a git pull --rebase repo-o branchname inside it,
  • or, if the git checkout fails (as you do not have that branch): checkout a new branch named after the repo-o's branch name and point it to repo-o's branchname.
  • If any of the two above succeed, push the newly created or updated branch name to your repo-f.

Season to taste; best tried on a newly created git clone of repo-f with the remote repo-o added to it, just in case things go wrong ;)

长发绾君心 2024-10-12 18:54:17

awk 版本有一些合并分支

sync_all_branch () {
  git fetch upstream
  for upstream_branch in   $( git branch -a |awk 'BEGIN {FS="/"} $2=="upstream" {print $3}' ) ;
  do
      if git checkout $upstream_branch
      then
          echo merge $upstream_branch
          git merge -s recursive -Xours upstream/$upstream_branch 
      else
          echo create $upstream_branch
          git checkout -b $upstream_branch upstream/$upstream_branch
      fi
  done
  git checkout master
  git push --all
}

awk version with some merge treaks

sync_all_branch () {
  git fetch upstream
  for upstream_branch in   $( git branch -a |awk 'BEGIN {FS="/"} $2=="upstream" {print $3}' ) ;
  do
      if git checkout $upstream_branch
      then
          echo merge $upstream_branch
          git merge -s recursive -Xours upstream/$upstream_branch 
      else
          echo create $upstream_branch
          git checkout -b $upstream_branch upstream/$upstream_branch
      fi
  done
  git checkout master
  git push --all
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文