Fork 倉庫 + 建立開發分支 + 同步 upstream 的完整流程

2025-04-05 16:50:17 | Github | 4 Reads

📌 1. Fork 倉庫

  • 在 GitHub 上打開原始倉庫(舉個例子):
    👉 https://github.com/Supalosa/supalosa-chronodivide-bot.git

  • 點右上角的 Fork,建立自己的副本


📌 2. 從自己 fork 的倉庫 clone 下來

git clone https://github.com/你的用戶名/supalosa-chronodivide-bot.git
cd supalosa-chronodivide-bot

此時 Git 自動設置的遠端:

origin -> 你自己的 fork 倉庫(可 push)

📌 3. 新建一個開發分支(可用任何名字)

git checkout -b your-feature-branch

替換 your-feature-branch 為你自己的開發分支名稱,例如 my-botfeature-abc 等。

 


📌 4. 添加原始倉庫作為 upstream(只做一次)

git remote add upstream https://github.com/Supalosa/supalosa-chronodivide-bot.git

確認遠端設置:

git remote -v

你應該會看到:

origin   https://github.com/你的用戶名/supalosa-chronodivide-bot.git (fetch)
origin   https://github.com/你的用戶名/supalosa-chronodivide-bot.git (push)
upstream https://github.com/Supalosa/supalosa-chronodivide-bot.git (fetch)
upstream https://github.com/Supalosa/supalosa-chronodivide-bot.git (push)

📌 5. 同步原始倉庫的更新

同步到本地主分支:

git checkout main
git fetch upstream
git merge upstream/main

如果要同步更新到你的開發分支:

git checkout your-feature-branch
git fetch upstream
git merge upstream/main

 


📌 6. 提交你的改動並推送到自己 fork 的倉庫

git add .
git commit -m "你的提交說明"
git push origin your-feature-branch

📌 7. 發 Pull Request 給原始倉庫

  • 前往你自己的 GitHub 倉庫頁面

  • 切到你剛推送的分支(如 your-feature-branch

  • 點「Compare & Pull Request」

  • 選擇原始倉庫作為目標,提交 PR ✅


✅ 備註:

  • origin:你自己的 fork(你可以 push)

  • upstream:原始作者的 repo(你只能 fetch / pull)


→GitBash使用手冊

This article was last edited at 2025-04-05 16:54:16