detached HEAD เกิดขึ้นเมื่อ HEAD ชี้ไปยัง commit โดยตรงแทนที่จะชี้ไปยัง branch มันเป็นสถานะปกติ (ไม่ใช่ error) ที่เกิดขึ้นเมื่อคุณ checkout commit, tag หรือ remote commit เฉพาะ — แต่การ commit ในสถานะนี้มีความเสี่ยงที่จะทำงานหาย ดังนั้นการเข้าใจมันจึงสำคัญ
ปกติ HEAD ชี้ไปที่อะไร
NORMALLY: HEAD → a BRANCH (e.g. main) → a commit
→ when you commit, the branch pointer advances, and HEAD follows it
DETACHED: HEAD → directly to a COMMIT (not through a branch)
→ you're \"not on any branch\" — looking at a specific commit
เมื่อใดที่ detached HEAD เกิดขึ้น
git checkout <commit-hash>
git checkout v1.0.0
git checkout origin/main
