💻 ติดตั้ง Git บนเครื่อง
Installing Git on Your Computer
🎯 Why Install Git Locally? / ทำไมต้องติดตั้ง Git?
English: Installing Git on your computer lets you work offline, use powerful command-line tools, and work faster than using GitHub's website!
ไทย: การติดตั้ง Git บนเครื่องให้คุณทำงานออฟไลน์ได้ ใช้เครื่องมือ command-line ที่ทรงพลัง และทำงานได้เร็วกว่าใช้เว็บไซต์ GitHub!
1ดาวน์โหลด Git / Download Git
สำหรับ Windows:
- ไปที่ https://git-scm.com
- คลิก "Download for Windows"
- เปิดไฟล์ที่ดาวน์โหลด
- คลิก "Next" ตลอด (ใช้ค่าเริ่มต้น)
- คลิก "Install"
สำหรับ Mac:
- เปิด Terminal
- พิมพ์: git --version
- ถ้ายังไม่มี Git จะถามให้ติดตั้ง Xcode Command Line Tools
English: For Windows, download from git-scm.com and install. For Mac, open Terminal and type "git --version" - it will prompt installation if needed.
2ตั้งค่า Git / Configure Git
เปิด Git Bash (Windows) หรือ Terminal (Mac/Linux) และพิมพ์:
English: Open Git Bash or Terminal and configure your name and email. This information will appear in your commits.
💡 Pro Tip / เคล็ดลับ
ใช้อีเมลเดียวกับที่ลงทะเบียน GitHub เพื่อให้คอมมิตแสดงโปรไฟล์ของคุณ!
English: Use the same email as your GitHub account so your commits link to your profile!
3ทดสอบการติดตั้ง / Test Installation
ถ้าเห็นเลขเวอร์ชัน เช่น git version 2.40.0 แสดงว่าติดตั้งสำเร็จ! 🎉
English: If you see a version number like "git version 2.40.0", installation was successful!
🌿 การทำงานกับ Branches
Working with Branches
🌳 What are Branches? / Branches คืออะไร?
English: Branches let you create separate versions of your project to try new features without affecting the main code. Think of it like creating a copy to experiment with!
ไทย: Branches ให้คุณสร้างเวอร์ชันแยกของโปรเจกต์เพื่อทดลองฟีเจอร์ใหม่โดยไม่กระทบโค้ดหลัก คิดเหมือนการสร้างสำเนาเพื่อทดลอง!
1ดู Branches ทั้งหมด / View All Branches
คำสั่งนี้แสดงรายการ branches ทั้งหมด Branch ที่มี * คือ branch ปัจจุบัน
English: This command shows all branches. The branch with * is your current branch.
2สร้าง Branch ใหม่ / Create a New Branch
สร้าง branch ชื่อ "feature-new-design" (แต่ยังไม่ได้ย้ายไป)
English: This creates a new branch called "feature-new-design" but doesn't switch to it yet.
3สลับไป Branch อื่น / Switch to Another Branch
หรือใช้คำสั่งใหม่:
English: Use "git checkout" or the newer "git switch" command to change branches.
⚡ Shortcut / ทางลัด
สร้างและสลับไปพร้อมกัน:
หรือ
4Merge Branches / รวม Branches
เมื่อฟีเจอร์เสร็จแล้ว ให้รวม (merge) กลับเข้า main:
- สลับกลับไป main: git checkout main
- Merge branch: git merge feature-new-design
English: When your feature is ready, switch back to main and merge your branch into it.
5ลบ Branch / Delete a Branch
ลบ branch หลังจาก merge เสร็จแล้ว (ใช้ -D ถ้าต้องการบังคับลบ)
English: Delete a branch after merging. Use -D to force delete if needed.
⌨️ คำสั่ง Git ที่สำคัญ
Essential Git Commands
📝 Basic Workflow / ขั้นตอนการทำงานพื้นฐาน
1Clone Repository / คัดลอกรีโพ
คัดลอก repository จาก GitHub มาเครื่องคุณ
English: Copy a repository from GitHub to your computer.
2Check Status / ตรวจสอบสถานะ
ดูว่าไฟล์ไหนเปลี่ยนแปลง ไฟล์ไหนพร้อม commit
English: Check which files have changed and which are ready to commit.
3Add Files / เพิ่มไฟล์
English: Add files to the staging area, preparing them for commit.
4Commit Changes / บันทึกการเปลี่ยนแปลง
บันทึกการเปลี่ยนแปลงพร้อมข้อความอธิบาย
English: Save your changes with a descriptive message.
5Push to GitHub / ส่งขึ้น GitHub
ส่งการเปลี่ยนแปลงจากเครื่องคุณไป GitHub
English: Send your changes from your computer to GitHub.
6Pull from GitHub / ดึงจาก GitHub
ดึงการเปลี่ยนแปลงล่าสุดจาก GitHub มาเครื่องคุณ
English: Get the latest changes from GitHub to your computer.
📊 Git Commands Reference / ตารางคำสั่ง Git
| Command / คำสั่ง | Description / คำอธิบาย |
|---|---|
git init |
สร้าง Git repository ใหม่ / Create new Git repository |
git status |
ดูสถานะไฟล์ / Check file status |
git add . |
เพิ่มไฟล์ทั้งหมด / Add all files |
git commit -m "message" |
บันทึกการเปลี่ยนแปลง / Save changes |
git push |
ส่งขึ้น GitHub / Upload to GitHub |
git pull |
ดึงจาก GitHub / Download from GitHub |
git branch |
ดู branches / List branches |
git checkout -b name |
สร้าง branch ใหม่ / Create new branch |
git merge name |
รวม branch / Merge branch |
git log |
ดูประวัติ commits / View commit history |
git diff |
ดูความแตกต่าง / See differences |
git remote -v |
ดู remote URLs / Show remote URLs |
🔀 Pull Requests
การขอรวมโค้ด
🤝 What is a Pull Request? / Pull Request คืออะไร?
English: A Pull Request (PR) is a way to ask the project owner to review and merge your changes. It's how teams collaborate on code!
ไทย: Pull Request (PR) คือวิธีขอให้เจ้าของโปรเจกต์ตรวจสอบและรวมการเปลี่ยนแปลงของคุณ เป็นวิธีที่ทีมทำงานร่วมกันบนโค้ด!
1Fork Repository / Fork รีโพ
ก่อนแก้ไขโปรเจกต์ของคนอื่น ให้ Fork ก่อน:
- ไปที่ repository ที่ต้องการ
- คลิกปุ่ม Fork มุมบนขวา
- ตอนนี้คุณมีสำเนาของรีโพในบัญชีของคุณ!
English: Click the Fork button to create your own copy of someone else's repository.
2Clone และแก้ไข / Clone and Edit
Clone รีโพที่ fork มา สร้าง branch ใหม่ และแก้ไข
English: Clone your forked repository, create a new branch, and make your changes.
3Push Branch / Push Branch
บันทึกและส่ง branch ของคุณไป GitHub
English: Commit your changes and push your branch to GitHub.
4สร้าง Pull Request / Create Pull Request
- ไปที่รีโพบน GitHub
- คลิก Pull requests
- คลิก New pull request
- เลือก branch ของคุณ
- เขียนคำอธิบายว่าเปลี่ยนอะไร
- คลิก Create pull request
English: On GitHub, click Pull requests, then New pull request. Choose your branch, describe your changes, and create the PR.
✍️ Good PR Description / คำอธิบาย PR ที่ดี
- อธิบายว่าแก้ไขอะไร (What changed)
- อธิบายว่าทำไม (Why)
- ระบุ issue ที่เกี่ยวข้อง (Related issues)
- ใส่ภาพหน้าจอถ้าเป็น UI (Screenshots for UI changes)
5รอการตรวจสอบ / Wait for Review
เจ้าของโปรเจกต์จะ:
- ตรวจสอบโค้ดของคุณ
- แสดงความคิดเห็น (Comment)
- ขอให้แก้ไข (Request changes)
- หรือ Merge เข้าโปรเจกต์!
English: The project owner will review your code, comment, request changes, or merge it into the project!
Excellent! You know how to create Pull Requests!
⚠️ แก้ไข Conflicts
Resolving Conflicts
🔥 What is a Conflict? / Conflict คืออะไร?
ไทย: Conflict เกิดเมื่อมีคนแก้ไขโค้ดส่วนเดียวกันในเวลาเดียวกัน Git ไม่รู้ว่าจะเลือกเวอร์ชันไหน
English: A conflict happens when two people edit the same part of code. Git doesn't know which version to keep!
1เมื่อเกิด Conflict / When Conflict Occurs
Git จะบอกว่าไฟล์ไหนมีปัญหา
English: Git tells you which files have conflicts.
2เปิดไฟล์และดู Conflict / Open File and See Conflict
Git ใส่เครื่องหมายพิเศษเพื่อแสดงส่วนที่ขัดแย้ง:
- <<<<<<< HEAD = โค้ดเวอร์ชันของคุณเริ่มต้น
- ======= = ตัวแบ่ง
- >>>>>>> branch-name = โค้ดเวอร์ชันอื่นจบ
English: Git marks the conflicting sections with special markers showing both versions.
3แก้ไข Conflict / Fix the Conflict
ลบเครื่องหมายพิเศษและเลือกโค้ดที่ถูกต้อง:
English: Delete the markers and keep the correct code. You can keep one version, the other, or combine both!
4บันทึกและ Commit / Save and Commit
หลังแก้ไขเสร็จ ให้ add และ commit ตามปกติ
English: After fixing, add and commit the resolved file.
💡 Preventing Conflicts / ป้องกัน Conflicts
- Pull บ่อยๆ เพื่อดึงโค้ดล่าสุด
- สื่อสารกับทีมว่าใครทำอะไร
- แบ่งงานให้คนละส่วน
- Commit บ่อยๆ เป็นชิ้นเล็กๆ
English: Pull often, communicate with your team, divide work clearly, and commit frequently in small pieces!
⭐ Best Practices
แนวปฏิบัติที่ดี
📝 Commit Messages / ข้อความ Commit
แนวปฏิบัติที่ดี:
- ใช้กริยาปัจจุบัน: "Add" ไม่ใช่ "Added"
- ชัดเจนและสั้น (50 ตัวอักษร)
- อธิบายว่า "อะไร" และ "ทำไม"
- ใช้ภาษาอังกฤษในโปรเจกต์ระหว่างประเทศ
🌿 Branch Naming / การตั้งชื่อ Branch
รูปแบบที่นิยม:
- feature/feature-name - ฟีเจอร์ใหม่
- bugfix/bug-description - แก้บั๊ก
- hotfix/urgent-fix - แก้เร่งด่วน
- docs/update-readme - เอกสาร
📁 .gitignore File
ไฟล์ .gitignore บอก Git ว่าอย่าติดตามไฟล์ไหนบ้าง:
English: The .gitignore file tells Git which files to ignore, like dependencies, environment variables, and build files.
Amazing! You know how to use Git and GitHub professionally!
🎓 สรุป
Summary
✅ สิ่งที่คุณได้เรียนรู้ / What You Learned
- ติดตั้งและตั้งค่า Git บนเครื่อง
- ทำงานกับ Branches
- คำสั่ง Git ที่สำคัญทั้งหมด
- สร้าง Pull Requests
- แก้ไข Merge Conflicts
- Best Practices สำหรับมืออาชีพ
English: You learned how to install Git, work with branches, use essential commands, create pull requests, resolve conflicts, and follow best practices!
🚀 Next Level / ระดับถัดไป
เรียนรู้ต่อไป:
- Git Rebase และ Cherry-pick
- Git Stash และ Reflog
- GitHub Actions (CI/CD)
- Git Hooks
- Advanced merging strategies
- Contributing to open source projects
🌟 Congratulations! / ยินดีด้วย!
ไทย: คุณมีความรู้ Git และ GitHub เพียงพอที่จะทำงานในทีมได้แล้ว! ต่อไปฝึกฝนโดยการสร้างโปรเจกต์และมีส่วนร่วมใน open source!
English: You now have enough Git and GitHub knowledge to work in a team! Practice by creating projects and contributing to open source!
💻 Happy Coding! / สนุกกับการเขียนโค้ด! 💻
Made with 💙 for Thai English Learners
สร้างด้วย 💙 สำหรับคนไทยที่กำลังเรียนภาษาอังกฤษ
📱 Keep pressing 🔊 to practice pronunciation!
กดปุ่ม 🔊 ต่อไปเพื่อฝึกการออกเสียง!