การดึงข้อมูลจาก remote

Git ระดับกลาง

George Boorman

Curriculum Manager, DataCamp

Remote vs. local

local และ remote branch ที่ remote branch มีไฟล์และไดเรกทอรีมากกว่า

Git ระดับกลาง

การทำงานร่วมกันในโปรเจกต์ Git

การซิงค์ข้อมูลระหว่าง local branch 5 branch กับ remote branch

Git ระดับกลาง

การ fetch จาก remote

  • ดึงข้อมูลจาก origin remote
git fetch origin
  • ดึงข้อมูลจาก remote branch ทั้งหมด

  • อาจสร้าง local branch ใหม่ หากมีเฉพาะใน remote

  • ไม่รวม (merge) เนื้อหาจาก remote เข้า local repo

Git ระดับกลาง

การ fetch remote branch

  • ดึงข้อมูลเฉพาะจาก branch main ของ origin remote
git fetch origin main
From https://github.com/datacamp/project
 * branch                main     -> FETCH_HEAD
Git ระดับกลาง

การซิงค์เนื้อหา

  • รวม (merge) default branch (main) ของ origin remote เข้ากับ branch ปัจจุบันใน local repo
git merge origin
Updating 9dcf4e5..887da2d
Fast-forward
 tests/tests.py | 13 +++++++++++++
 README.md     | 10 ++++++++++
 2 files changed, 23 insertions (+)
Git ระดับกลาง

การ pull จาก remote

  • การซิงค์ระหว่าง local และ remote เป็น workflow ที่ใช้บ่อย
  • Git ช่วยให้กระบวนการนี้ง่ายขึ้น!

  • fetch และ merge จาก default branch (main) ของ remote เข้ากับ branch ปัจจุบันใน local repo

git pull origin
Git ระดับกลาง

การ pull remote branch

  • pull จาก branch dev ของ origin remote
git pull origin dev
  • ยังคง merge เข้ากับ local branch ที่อยู่ในขณะนั้น!
Git ระดับกลาง

ผลลัพธ์ของ git pull

From https://github.com/datacamp/project
 * branch                dev     -> FETCH_HEAD
Updating 9dcf4e5..887da2d
Fast-forward
 tests/tests.py | 13 +++++++++++++
 README.md     | 10 ++++++++++
 2 files changed, 23 insertions (+)
Git ระดับกลาง

ข้อควรระวัง

git pull origin
Updating 9dcf4e5..887da2d
error: Your local changes to the following files would be overwritten by merge:
       README.md
Please commit your changes or stash them before you merge.
Aborting
  • ควร save การเปลี่ยนแปลงใน local ก่อน pull จาก remote
Git ระดับกลาง

มาฝึกกันเถอะ!

Git ระดับกลาง

Preparing Video For Download...