电脑维修 笔记本维修 手机维修 打印机维修 IT外包
24小时服务电话:0731-84688748  18229718750
地址:长沙市天心区青园街道友谊社区友谊小区A3栋15号

服务区域:湖南省政府方圆5公里内(友谊社区 青园小区 阳光嘉园 天一康园 湘超景园 国际公寓 HOPSCA写字楼 豪布斯卡 天城·泰祥苑 国检园 梦网景园 石人村金石·蓉园安置小区 鑫隆家园 湘诚嘉园 童话里 七星车城 华铁佳苑 巢之恋 鑫远杰座 鑫远华城 满庭芳 宽域 鑫天山水洲城 星语林名园 青园街道进湾子社区 白沙世纪佳园 长沙欧洲城 长沙奥林匹克花园 高升安置小区 湘府名邸 嘉尚君远 富景园 鑫源公寓 岳泰理想城 等等...)

Github github.com自动同步Sync fork上游项目代码仓库 - 全文内容:

显示技术博客列表

Github github.com自动同步Sync fork上游项目代码仓库

超短链接

Github github.com自动同步Sync fork上游项目代码仓库

https://github.com/ 

1、添加.github/workflows/sync-upstream.yml文件:

2、找到当前的主要分支是main还是master:

3、.github/workflows/sync-upstream.yml文件内容:

name: Sync Upstream

on:
  schedule:
    - cron: '0 0 * * *' # 每天 00:00 UTC 运行
  workflow_dispatch:  # 允许手动触发

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: 检出你的 Fork 仓库
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: 配置 Git 用户信息
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"

      - name: 配置 GitHub 身份验证
        run: |
          git config --global credential.helper 'store'
          echo "https://github-actions[bot]:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials

      - name: 添加上游仓库,与保留本地.github/workflows/ 目录内容不更新
        run: |
          git remote add upstream https://github.com/Guovin/iptv-api.git || true # 这里改为你的上游仓库
          git fetch upstream
          git checkout master  # 这里改为你的上游主要分支,一般可能是main或者master
          git checkout -b temp-merge  # 创建一个临时分支
          git merge -X theirs upstream/master --allow-unrelated-histories  # 默认保留上游代码 这里改为你的上游主要分支,一般可能是main或者master
          git checkout master  # 回到主分支这里改为你的上游主要分支,一般可能是main或者master
          rsync -a .github/workflows/ ../workflows-backup/  # 备份工作流目录
          git reset --hard temp-merge  # 硬重置到合并后的状态
          rsync -a ../workflows-backup/ .github/workflows/  # 恢复工作流目录
          rm -rf ../workflows-backup  # 删除临时备份
          git add .github/workflows/
          git commit -m "同步上游代码,并保留本地 workflows" || true
          git branch -D temp-merge  # 删除临时分支

      - name: 推送到 Fork 仓库
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git push origin master --force --no-verify  # 这里改为你的上游主要分支,一般可能是main或者master

也可以直接下载模板文件:

_.github_workflows_sync-upstream-模板.rar (可能上漩更新新增了上游计划导致同步失败)


20250309模板修定版本2,修复上游新增计划文件后导致失败问题:

_.github_workflows_sync-upstream-模板-修定版本2.rar

 20250309模板修定版本2,文件内容:

name: Sync Upstream

on:
  schedule:
    - cron: '0 0 * * *' # 每天 00:00 UTC 运行
  workflow_dispatch:  # 允许手动触发

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: 检出你的 Fork 仓库
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: 配置 Git 用户信息
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"

      - name: 配置 GitHub 身份验证
        run: |
          git config --global credential.helper 'store'
          echo "https://github-actions[bot]:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials

      - name: 添加上游仓库,并保留本地 .github/workflows/ 目录
        run: |
          git remote add upstream https://github.com/cmliu/CF-Workers-docker.io || true # 这里改为你的上游仓库
          git fetch upstream
          git checkout main # 这里改为你的上游主要分支,一般可能是main或者master
          git checkout -b temp-merge # 创建一个临时分支
          
          # 先合并上游,但跳过 .github/workflows 目录
          git read-tree --prefix=.github/workflows/ -u HEAD  # 备份本地 .github/workflows/
          git merge -X theirs upstream/main --allow-unrelated-histories || true # 默认保留上游代码,但 .github/workflows/ 目录不会被影响。
          git checkout HEAD -- .github/workflows/  # 恢复本地的 .github/workflows/ 目录,确保合并不会覆盖它
          
          git checkout main # 回到主分支,一般可能是main或者master
          git reset --hard temp-merge  # 硬重置到合并后的状态
          git branch -D temp-merge # 删除临时分支
          
          git add .github/workflows/  # 添加之前备份的本地 .github/workflows/
          git commit -m "同步上游代码,并保留本地 .github/workflows/" || true

      - name: 推送到 Fork 仓库
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git push origin main --force --no-verify  # 这里改为你的上游主要分支,一般可能是main或者master