github - 可以在 GitHub 中自动同​​步 fork 吗?

标签 github git-fork

如果选中,Stash 将启用自动 fork 同步:
https://confluence.atlassian.com/display/STASH/Keeping+forks+synchronized
它将更新您尚未修改的 fork 中的任何分支。
我一直无法在 GitHub 中找到类似的自动功能;所有的谷歌搜索都在寻找通过本地缓存同步 fork 的手动方式。

最佳答案

作为记录,最近我遇到了同样的问题,并通过 Github Actions 解决了这个问题。解决方案相当简单:计划的操作获取上游存储库并将其合并到我的存储库中。

# .github/workflows/example.yml

name: Merge upstream branches
on:
  schedule:
     # actually, ~5 minutes is the highest
     # effective frequency you will get
    - cron:  '* * * * *'
jobs:
  merge:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Merge upstream
        run: |
          git config --global user.name 'your-name'
          git config --global user.email 'your-username@users.noreply.github.com'

          # "git checkout master" is unnecessary, already here by default
          git pull --unshallow  # this option is very important, you would get
                                # complains about unrelated histories without it.
                                # (but actions/checkout@v2 can also be instructed
                                # to fetch all git depth right from the start)

          git remote add upstream https://github.com/example/test.git
          git fetch upstream

          # Neither forget the -b opt,
          # the feature/x ref is ambiguous at this stage
          git checkout -b feature/x origin/feature/x
          git merge --no-edit upstream/feature/x
          git push origin feature/x

          git checkout master
          git merge --no-edit upstream/master
          git push origin master

          # etc


我每周日运行它,这对我来说绰绰有余。只需将其安排到适合您的任何地方。

此外,同步不同作业中的每个分支可能更明智,因为它们将并行运行,并且在发生冲突时可以独立成功或失败。

如果需要合并任意数量的分支,可以引用 How to fetch all Git branches 之类的问题找到外壳技巧来做到这一点。

我注意到存在一个公共(public)行动来通过重新定位来解决这个问题。它看起来很有希望,但它没有记录,所以这里是我的片段。希望能帮助到你!

关于github - 可以在 GitHub 中自动同​​步 fork 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23793062/

相关文章:

c++ - Github 的 CodeFactor 提示简单函数的复杂性

version-control - 我如何通知所有分支我的代码发生了重大变化?

git - 用原来的账号fork一个 fork 的项目

Git 同步到上游 : Newly created branch not showing in my fork

git - 如何更新 fork 的 git 仓库?

git - Bitbucket:更新 fork 以 merge master repo 的更改?

jquery - 使用 GitHub API V3 从组织获取私有(private) repo

typescript - 模块分辨率 : NPM Install Typescript package from Github

python - 如何将 GitHub Actions 工作流程验证为 GitHub 应用程序,以便它可以触发其他工作流程?

git - 从远程 git 存储库中查找最新的 git 标签