Git 106: ใช้ Git กับ AI agent อย่างปลอดภัยGit 106: use Git safely with AI agents
ปิด Git 10x ด้วย workflow ที่ปลอดภัยสำหรับทำงานกับ AI: status clean, branch มีขอบเขต, review diff, commit hygiene และพื้นฐานการกู้คืนFinish Git 10x with a safe AI-assisted workflow: clean status, scoped branch, diff review, commit hygiene, and recovery basics.
Git becomes more important when AI can edit files for you.
The goal is not to block AI. The goal is to make every change inspectable.
Start clean
Before asking an AI agent to edit a project:
git status
If the tree is dirty, decide what the changes are.
- Commit work that is ready.
- Move unrelated work away.
- Tell the agent which files are already changed and must not be overwritten.
Do not let an AI task start from a confusing state.
Create a scoped branch
Use a branch per task:
git switch -c fix-workshop-copy
The branch name should explain the job.
Bad:
ai-stuff
Better:
docs-git-10x-lessons
Give the agent file boundaries
A strong AI instruction includes ownership:
Edit only:
- src/content/workshops/git-10x/*.mdx
- src/lib/catalog.ts
Do not edit:
- src/styles/globals.css
- database schema
- unrelated workshop content
Before finalizing, summarize changed files and tests run.
This works because Git can later verify whether the boundary was respected.
Review the diff, not the vibe
After the agent finishes:
git status
git diff
If you already staged changes:
git diff --staged
Look for:
- unrelated files
- deleted content
- changed URLs or slugs
- secrets
- claims that need sources
- tests that should be updated
Do not commit until the diff makes sense.
Commit in meaningful chunks
If one AI run changed many things, split commits by purpose.
Example:
docs: add Git 10x lessons
catalog: register Git 10x workshop
docs: update free workshop central plan
Small commits make review and rollback easier.
Basic recovery habits
Use recovery commands carefully.
Helpful read-only checks:
git status
git log --oneline -10
git diff
Common recovery ideas:
- If a file is not staged and you do not want the change, restore that file.
- If changes are staged but not committed, unstage before deciding.
- If a commit is wrong but already shared, prefer a new corrective commit or
git revertinstead of rewriting shared history.
When in doubt, stop and ask. Many Git mistakes become worse when you panic-run commands.
Final AI + Git workflow
Use this as your default loop:
1. git status
2. create or choose a task branch
3. tell AI the goal and file boundaries
4. let AI edit
5. git status
6. git diff
7. run tests or checks
8. git add specific files
9. git diff --staged
10. git commit with a clear message
11. push and open review if needed
The point is not ceremony. The point is control.
Git 10x final checklist
- You know Git is local version control, not GitHub.
- You can create a repository and read status.
- You can inspect diffs before staging.
- You can make meaningful commits.
- You can use branches for isolated work.
- You understand remotes, pull, push, and where GitHub fits.
- You can use Git as a safety rail for AI-assisted edits.
References
Git สำคัญขึ้นมากเมื่อ AI แก้ไฟล์แทนคุณได้
เป้าหมายไม่ใช่การกัน AI ออกไป แต่คือทำให้ทุก change ตรวจได้
เริ่มจากสถานะ clean
ก่อนให้ AI agent แก้ project:
git status
ถ้า tree dirty ให้ตัดสินใจก่อนว่า change เหล่านั้นคืออะไร
- commit งานที่พร้อมแล้ว
- ย้ายงานที่ไม่เกี่ยวออกไป
- บอก agent ว่าไฟล์ไหนมี change อยู่แล้วและห้าม overwrite
อย่าเริ่มงาน AI จาก state ที่สับสน
สร้าง branch ที่มีขอบเขต
ใช้ branch แยกตาม task:
git switch -c fix-workshop-copy
ชื่อ branch ควรอธิบายงาน
ไม่ดี:
ai-stuff
ดีขึ้น:
docs-git-10x-lessons
ให้ขอบเขตไฟล์กับ agent
instruction ที่ดีควรบอก ownership:
Edit only:
- src/content/workshops/git-10x/*.mdx
- src/lib/catalog.ts
Do not edit:
- src/styles/globals.css
- database schema
- unrelated workshop content
Before finalizing, summarize changed files and tests run.
สิ่งนี้ใช้ได้เพราะ Git ตรวจทีหลังได้ว่า agent เคารพขอบเขตหรือไม่
Review diff ไม่ใช่ความรู้สึก
หลัง agent ทำเสร็จ:
git status
git diff
ถ้า stage change แล้ว:
git diff --staged
มองหา:
- ไฟล์ที่ไม่เกี่ยว
- content ที่ถูกลบ
- URL หรือ slug ที่เปลี่ยน
- secret
- claim ที่ต้องมี source
- test ที่ควรถูก update
อย่า commit จนกว่า diff จะสมเหตุสมผล
Commit เป็นก้อนที่มีความหมาย
ถ้า AI run เดียวเปลี่ยนหลายอย่าง ให้แยก commit ตามเป้าหมาย
ตัวอย่าง:
docs: add Git 10x lessons
catalog: register Git 10x workshop
docs: update free workshop central plan
commit ที่เล็กทำให้ review และ rollback ง่ายขึ้น
พื้นฐานการกู้คืน
ใช้ recovery command อย่างระวัง
คำสั่งตรวจแบบ read-only:
git status
git log --oneline -10
git diff
แนวคิด recovery ที่เจอบ่อย:
- ถ้าไฟล์ยังไม่ staged และไม่ต้องการ change นั้น ให้ restore เฉพาะไฟล์นั้น
- ถ้า change staged แล้วแต่ยังไม่ commit ให้ unstage ก่อนตัดสินใจ
- ถ้า commit ผิดแต่ share แล้ว ให้ใช้ corrective commit ใหม่หรือ
git revertแทนการ rewrite shared history
ถ้าไม่แน่ใจ ให้หยุดและถาม ความผิดพลาดของ Git หลายอย่างแย่ลงเพราะรัน command ตอนตกใจ
Workflow สุดท้ายสำหรับ AI + Git
ใช้เป็น loop หลัก:
1. git status
2. create or choose a task branch
3. tell AI the goal and file boundaries
4. let AI edit
5. git status
6. git diff
7. run tests or checks
8. git add specific files
9. git diff --staged
10. git commit with a clear message
11. push and open review if needed
ประเด็นไม่ใช่พิธีกรรม แต่คือ control
Checklist สุดท้ายของ Git 10x
- คุณรู้ว่า Git คือ local version control ไม่ใช่ GitHub
- คุณสร้าง repository และอ่าน status ได้
- คุณตรวจ diff ก่อน staging ได้
- คุณสร้าง commit ที่มีความหมายได้
- คุณใช้ branch เพื่อแยกงานได้
- คุณเข้าใจ remote, pull, push และตำแหน่งของ GitHub
- คุณใช้ Git เป็น safety rail สำหรับงานที่มี AI ช่วยแก้ได้
References
เข้าสู่ระบบเพื่อบันทึกความคืบหน้าSign in to track your progress
เข้าสู่ระบบSign in→