เมื่อ repo หลักมีการอัพเดทเราจะทำให้ตัว fork repo อัพเดทได้โดยใช้วิธีต่อไปนี้

1.ให้เปิด cmd (Command Prompt) หรือ Git Bash. ใน folder ที่เรา clone มา

2. จากนั้นให้เพิ่ม repo หลักไปที่ remote add name (สามารถระบุชื่อเองตามที่ต้องการได้ แต่ตัวอย่างจะใช้ upstream และ url ต้องเป็น git repo หลักเท่านั้น) โดยใช้คำสั่ง

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

3. เมื่อเพิ่มเรียบร้อยให้ใช้คำสั่ง git remote -v เพื่อทำการเช็คแล้วจะมีตัว upstream ขึ้นมา

$ git remote -vผลลัพธ์  
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
> upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

4. วิธีการอัพเดท fork repo ด้วยการ fetch & rebase โดยใช้คำสั่ง

$ git fetch upstream main 
$ git rebase upstream/main
$ git push

--

--