Introduction to remotes

Git ระดับกลาง

George Boorman

Curriculum Manager, DataCamp

Local repo

local repository inside a desktop computer

Git ระดับกลาง

Remote repo

remote repo in the cloud

Git ระดับกลาง

ทำไมต้องใช้ remote repos?

ประโยชน์ของ remote repos

  • ข้อมูลได้รับการสำรองไว้เสมอ

  • ทำงานร่วมกันได้ทุกที่

view of a laptop looking across a rooftop and a lake

Git ระดับกลาง

การ clone repo

  • สำเนา repo บนเครื่องของเรา = local remotes

  • การทำสำเนา = cloning

git clone path-to-project-repo
  • Cloning โปรเจกต์ในเครื่อง
git clone /home/george/repo
  • Cloning และตั้งชื่อโปรเจกต์ในเครื่อง
git clone /home/george/repo new_repo
Git ระดับกลาง

การ clone remote

  • Remote repos มักเก็บไว้บนบริการโฮสต์ออนไลน์

    • เช่น GitHub, Bitbucket หรือ GitLab
  • หากมีบัญชีผู้ใช้:

    • สามารถ clone remote repo ลงบนเครื่องของเราได้
git clone URL
git clone https://github.com/datacamp/project
Git ระดับกลาง

การระบุ remote

  • เมื่อ clone repo

    • Git จะจำตำแหน่งของต้นฉบับไว้
  • Git เก็บ tag ของ remote ไว้ในการตั้งค่าของ repo ใหม่

  • แสดงรายการ remotes ทั้งหมดที่เชื่อมกับ repo

git remote
datacamp
Git ระดับกลาง

การดูข้อมูลเพิ่มเติม

  • ดูข้อมูลเพิ่มเติมเกี่ยวกับ remote
git remote -v
datacamp     https://github.com/datacamp/project (fetch)
datacamp     https://github.com/datacamp/project (pull)
Git ระดับกลาง

การสร้าง remote

  • เมื่อ clone Git จะตั้งชื่อ remote ว่า origin โดยอัตโนมัติ
git remote add name URL
  • สร้าง remote ชื่อ george
git remote add george https://github.com/george_datacamp/repo
  • การตั้งชื่อ remote มีประโยชน์สำหรับการ merge
Git ระดับกลาง

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

Git ระดับกลาง

Preparing Video For Download...