[💻] การเขียน Git Branch
[17 February 2025]
มาตรฐานการตั้งชื่อ Branch
รูปแบบมาตรฐาน
<type>/<issue-ID>-<short-description>
<type>
: ประเภทของ branch<issue-ID>
: หมายเลขอ้างอิงจาก issue หรือ task tracker (ถ้ามี)<short-description>
: คำอธิบายสั้น ๆ เกี่ยวกับ branch
ประเภทของ Branch
1️⃣ Main Branches
Branch หลักที่ใช้ในโครงการ:
main
หรือmaster
→ Branch หลักที่ใช้สำหรับ productiondevelop
→ Branch ที่ใช้สำหรับการพัฒนา
2️⃣ Feature Branches
ใช้สำหรับพัฒนา feature ใหม่
feature/123-add-user-authentication
✅ ตัวอย่าง:
feature/101-add-payment-gateway
feature/205-improve-dashboard-ui
3️⃣ Bug Fix Branches
ใช้สำหรับแก้ไขบั๊ก
fix/456-fix-login-issue
✅ ตัวอย่าง:
fix/302-fix-incorrect-tax-calculation
fix/789-fix-responsive-navbar
4️⃣ Hotfix Branches
ใช้สำหรับแก้ไขปัญหาเร่งด่วนที่กระทบ production
hotfix/999-critical-security-patch
✅ ตัวอย่าง:
hotfix/777-patch-vulnerability-xss
hotfix/888-fix-payment-gateway-error
5️⃣ Release Branches
ใช้สำหรับเตรียมการปล่อยเวอร์ชันใหม่
release/v1.2.0
✅ ตัวอย่าง:
release/v2.0.0
release/v1.5.3
6️⃣ Chore Branches
ใช้สำหรับงานเบ็ดเตล็ด เช่น อัปเดต dependencies หรือปรับปรุงโครงสร้างโค้ด
chore/update-dependencies
✅ ตัวอย่าง:
chore/refactor-api-endpoints
chore/upgrade-nodejs-18
7️⃣ Experimental Branches
ใช้สำหรับการทดลอง เช่น POC (Proof of Concept)
experiment/new-ai-algorithm
✅ ตัวอย่าง:
experiment/test-react-query
experiment/try-serverless-architecture
แนวปฏิบัติที่ดี
- ✅ ตั้งชื่อให้กระชับและชัดเจน → ใช้ขีดกลาง (-) แยกคำ
- ✅ ใช้ issue ID (ถ้ามี) → ช่วยให้เชื่อมโยงกับ task tracker ได้ง่าย
- ✅ เลี่ยงการใช้ชื่อทั่วไป เช่น new-feature หรือ fix-bug
- ✅ ใช้ตัวอักษรพิมพ์เล็กทั้งหมด → ลดปัญหาความแตกต่างของระบบไฟล์ (เช่น macOS, Linux, Windows)
📌 สรุป
feature/xxx-description
→ ใช้สำหรับเพิ่มฟีเจอร์ใหม่fix/xxx-description
→ ใช้สำหรับแก้ไขบั๊กhotfix/xxx-description
→ ใช้สำหรับแก้ไขปัญหาเร่งด่วนrelease/vX.X.X
→ ใช้สำหรับเตรียมการปล่อยเวอร์ชันchore/xxx-description
→ ใช้สำหรับงานเบ็ดเตล็ดexperiment/xxx-description
→ ใช้สำหรับการทดลองฟีเจอร์ใหม่ ๆ
การใช้มาตรฐานนี้จะช่วยให้ workflow ของทีมชัดเจนขึ้นและลดความสับสนในการทำงานกับ Git 💡