615 字
3 分钟
让Fork自主进化:nextjs-notion-starter-kit 自动同步主仓库
2025-03-20
无标签

好的!我们一步步来搞定 Fork、自动同步和分支管理

🎯 目标#

  1. Fork 这个项目到你的 GitHub 仓库
  2. 配置自动同步,让 fork 的代码保持和上游更新
  3. 创建自己的分支用于开发,确保不影响主分支

🔧 1. Fork 仓库#

  1. 打开这个项目页面:nextjs-notion-starter-kit

  2. 点击右上角 Fork,选自己的账户或组织

  3. Fork 完成后你自己的仓库地址类似:

    https://github.com/你的用户名/nextjs-notion-starter-kit

🔧 2. 克隆仓库到本地#

git clone git@github.com:你的用户名/nextjs-notion-starter-kit.git
cd nextjs-notion-starter-kit

🔧 3. 添加上游(upstream)仓库地址#

保持和原作者仓库同步:

git remote add upstream https://github.com/transitive-bullshit/nextjs-notion-starter-kit.git

🔍 确认远程地址:

git remote -v

应该显示:

origin    git@github.com:你的用户名/nextjs-notion-starter-kit.git (fetch)
upstream  https://github.com/transitive-bullshit/nextjs-notion-starter-kit.git (fetch)

🔧 4. 拉取上游更新并合并#

你可以手动同步(自动同步在后面讲)

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

🔧 5. 新建自己的开发分支#

主分支同步 upstream,开发在自己分支

git checkout -b dev
git push origin dev

🔧 6. 自动同步设置#

方法一:GitHub Actions 自动同步(推荐)#

👉 项目地址#

https://github.com/wei/git-sync

快速配置:#

  1. 进入你的仓库,点击 ActionsNew workflow
  2. 选择 set up a workflow yourself
  3. 添加如下 YAML 文件(例如 .github/workflows/sync-upstream.yml
name: Sync Fork

on:
  schedule:
    - cron: '0 0 * * *' # 每天同步一次
  workflow_dispatch:

jobs:
  sync:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout destination repo
        uses: actions/checkout@v3

      - name: Setup SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          git config --global --add safe.directory /github/workspace

      - name: Sync upstream repo
        run: |
          git clone git@github.com:sylarxiong/nextjs-notion-starter-kit.git repo
          cd repo
          git remote add upstream git@github.com:transitive-bullshit/nextjs-notion-starter-kit.git
          git fetch upstream
          git merge upstream/main
          git push origin main
  1. 配置 SSH KEY
    • 本地生成 SSH key:

      ssh-keygen -t ed25519 -C "your_email@example.com"
    • 把私钥(id_ed25519)添加到你的 GitHub 仓库 Secrets:

      • SettingsSecrets and variablesActionsNew repository secret
      • Name 填 SSH_PRIVATE_KEY,Value 填私钥内容
    • 公钥(id_ed25519.pub)添加到你的 GitHub 账户 SSH keys

      • SettingsSSH and GPG keysNew SSH Key

方法二:GitHub 官方 Fork Sync 功能(适合主分支同步,不适合复杂分支)#

进入 Fork 仓库 → Sync Fork 按钮 → Update branch

适合手动操作,自动化不如 GitHub Actions 灵活。


✅ 最终结构建议#

  • main 分支 → 只同步 upstream(保持纯净)
  • dev 分支 → 自己开发,功能提交
  • feature/* → 细化分支管理(可选)

🚀 全流程总结#

  1. Fork 项目 → https://github.com/你的用户名/nextjs-notion-starter-kit
  2. clone 到本地
  3. 配置 upstream 并同步
  4. dev 分支开发
  5. 配置 GitHub Actions 自动同步
  6. 定期合并 main → dev,保持最新代码

让Fork自主进化:nextjs-notion-starter-kit 自动同步主仓库
https://fuwari.vercel.app/posts/notion/1bc1e586b234801fbfe5e6ce9410d67a/
作者
Finn
发布于
2025-03-20
许可协议
CC BY-NC-SA 4.0