หน่วยที่ 7 การใช้ Git

เรียนรู้การควบคุมเวอร์ชันของโค้ดด้วย Git

7.1 Git คืออะไร

Git คือ ระบบควบคุมเวอร์ชัน (Version Control System) ที่ช่วยติดตามการเปลี่ยนแปลงของโค้ด

Git ช่วยให้สามารถย้อนกลับเวอร์ชัน และทำงานเป็นทีมได้

7.2 ประโยชน์ของ Git

7.3 คำสั่งพื้นฐาน Git

เริ่มต้น Git:

git init

เพิ่มไฟล์:

git add .

บันทึก:

git commit -m "first commit"

ดูสถานะ:

git status

7.4 ขั้นตอนการใช้งาน Git

  1. แก้ไขไฟล์
  2. git add .
  3. git commit
  4. git push

7.5 GitHub คืออะไร

GitHub คือ เว็บไซต์สำหรับเก็บโค้ดออนไลน์

git remote add origin https://github.com/user/repo.git
git push -u origin main

Workshop 1: เริ่มต้น Git

Step 1 เปิด Terminal

git init

Step 2 เพิ่มไฟล์

git add .

Step 3 Commit

git commit -m "My website"

Workshop 2: เชื่อมต่อ GitHub

git remote add origin https://github.com/user/repo.git
git branch -M main
git push -u origin main

7.6 ตัวอย่างสถานการณ์จริง

แก้ไขไฟล์ index.html

ใช้คำสั่ง:

git add index.html
git commit -m "update index"
git push

สรุป