What Is Git? — Git คืออะไร?
🇹🇭 ภาษาไทย
🇬🇧 English
Git is a program that helps you track changes in your files. Think of it like save points for your code. You can save snapshots, view the history of every change, and go back to any previous version at any time. Developers all over the world use Git every day.
Why Does This Matter? — ทำไมถึงสำคัญ?
- Never lose work — ไม่มีวันสูญเสียงาน แม้จะลบไฟล์ไปแล้ว
- See what changed and when — ดูได้ว่ามีอะไรเปลี่ยนแปลงและเมื่อไหร่
- Work with a team without conflicts — ทำงานกับทีมโดยไม่เกิดความขัดแย้ง
- Try new ideas safely on branches — ทดลองไอเดียใหม่ได้อย่างปลอดภัยบน branch
- Required for almost every tech job — จำเป็นสำหรับงานด้าน IT แทบทุกตำแหน่ง
Useful Phrases — วลีที่มีประโยชน์
What You Need — สิ่งที่ต้องมี
🇹🇭 ภาษาไทย
ก่อนเริ่มต้น คุณต้องติดตั้งและตั้งค่าสิ่งเหล่านี้:
🇬🇧 English
Before you start, you need to install and configure these things:
Free download from git-scm.com. Works on Windows, Mac, and Linux.
Windows: Git Bash comes with Git. Mac/Linux: use the built-in Terminal.
Sign up free at github.com — needed for remote collaboration.
VS Code (free) is recommended — it has built-in Git support.
Part 1: Core Concepts — แนวคิดหลัก
1 Repository — ที่เก็บโค้ด
🇹🇭 ภาษาไทย
A
มีสองประเภท: local repo (อยู่บนคอมพิวเตอร์ของคุณ) และ remote repo (อยู่บนเซิร์ฟเวอร์เช่น GitHub)
🇬🇧 English
A repository (or "repo") is a folder that Git manages — it stores all your files and the complete history of every change. Every project has its own repo.
There are two types: a local repo (on your computer) and a remote repo (on a server like GitHub).
2 Commit — การบันทึกการเปลี่ยนแปลง
🇹🇭 ภาษาไทย
A
🇬🇧 English
A commit is Git's "save" action — it records the state of your files at that moment, along with a message describing what you changed. Think of it as a checkpoint in a game. Each commit has a unique ID.
3 Branch — สาขา
🇹🇭 ภาษาไทย
A
🇬🇧 English
A branch is a separate line of development. You can experiment on a branch without affecting the main code. When ready, you merge it back. The default branch is called main (or sometimes master).
4 Push and Pull — ส่งขึ้นและดึงลง
🇹🇭 ภาษาไทย
คำสั่งเหล่านี้ทำให้ local และ remote
🇬🇧 English
Push sends your commits from your local repo to the remote repo (like GitHub).
Pull downloads the latest changes from the remote repo to your local repo.
These commands keep your local and remote repositories in sync.
🎉 Concepts Clear! — เข้าใจแนวคิดพื้นฐานแล้ว!
ตอนนี้คุณรู้จัก repository, commit, branch, push และ pull แล้ว! ในส่วนถัดไปเราจะฝึกใช้คำสั่งจริงๆ
Now you know repository, commit, branch, push, and pull. In the next section we will practice the real commands!
Tech Phrases — วลีในงาน IT
Part 2: Essential Commands — คำสั่งสำคัญ
🇹🇭 ภาษาไทย
คำสั่ง Git ทั้งหมดเริ่มต้นด้วยคำว่า git แล้วตามด้วยคำสั่งย่อย เช่น git commit หรือ git push คุณพิมพ์คำสั่งเหล่านี้ใน
🇬🇧 English
All Git commands start with the word git followed by a subcommand, for example git commit or git push. You type these commands in the terminal (command line).
1 Setting Up Git — ตั้งค่า Git ครั้งแรก
🇹🇭 ภาษาไทย
ครั้งแรกที่ใช้ Git ให้บอก Git ว่าคุณเป็นใคร คำสั่งนี้ต้องทำเพียงครั้งเดียวบนคอมพิวเตอร์ของคุณ:
🇬🇧 English
The first time you use Git, tell it who you are. This only needs to be done once on your computer:
2 Starting a Repository — เริ่มต้น Repository
🇹🇭 ภาษาไทย
มีสองวิธีในการเริ่มต้น: สร้าง repo ใหม่บนคอมพิวเตอร์ของคุณ หรือ
🇬🇧 English
There are two ways to start: create a brand new repo on your computer, or clone an existing repo from a remote server like GitHub.
3 The Basic Workflow — ขั้นตอนการทำงานพื้นฐาน
🇹🇭 ภาษาไทย
วงจรการทำงานปกติกับ Git มีสามขั้นตอนหลัก:
- แก้ไขหรือสร้างไฟล์
- เพิ่มไฟล์เข้า
staging area ด้วยgit add - บันทึกการเปลี่ยนแปลงด้วย
git commit - ส่งขึ้น remote ด้วย
git push
🇬🇧 English
The regular Git workflow has three main steps: stage → commit → push.
- Edit or create files
- Add files to the staging area with
git add - Save a snapshot with
git commit - Send to remote with
git push
4 Working with Branches — ทำงานกับ Branch
🇹🇭 ภาษาไทย
ทำงานบน
🇬🇧 English
Always work on a new branch when developing a new feature. Avoid working directly on the main branch — this protects your stable code.
5 Viewing History — ดูประวัติ
🇹🇭 ภาษาไทย
คำสั่ง git log แสดงประวัติ commit ทั้งหมด และ git diff แสดงสิ่งที่เปลี่ยนแปลงในแต่ละ
🇬🇧 English
The git log command shows the full commit history. git diff shows exactly what changed in each file.
🎉 You Can Use Git! — คุณใช้ Git เป็นแล้ว!
ด้วยคำสั่งเหล่านี้ คุณสามารถทำงานกับ Git ได้แล้วในชีวิตจริง! ส่วนถัดไปจะแนะนำการทำงานกับ GitHub และเพื่อนร่วมทีม
With these commands you can use Git in real life! The next section covers working with GitHub and collaborating with a team.
Workflow Phrases — วลีในกระบวนการทำงาน
Part 3: GitHub & Collaboration — ทำงานร่วมกันบน GitHub
🇹🇭 ภาษาไทย
🇬🇧 English
GitHub is a website that stores Git repositories online, letting you collaborate with developers anywhere in the world. It is free for public projects.
1 Fork and Clone — Fork และ Clone
🇹🇭 ภาษาไทย
🇬🇧 English
A fork copies someone else's repo to your own GitHub account. Then you can clone it to your computer, make changes, and propose them back to the original project.
2 Pull Request — การขอ merge โค้ด
🇹🇭 ภาษาไทย
A
🇬🇧 English
A pull request (PR) is a request to merge your code into the main repository. The project owner will review your code before merging. This is the heart of open-source collaboration.
Good Commit Message Rules — กฎการเขียน commit message ที่ดี
ข้อความ commit ที่ดีช่วยให้ทีมเข้าใจว่าเกิดอะไรขึ้น / Good commit messages help your team understand what happened:
- Use the imperative mood — "Add login page" ไม่ใช่ "Added login page"
- Be specific — "Fix bug in user authentication" ดีกว่า "Fix bug"
- Keep it short — ไม่เกิน 72 ตัวอักษรในบรรทัดแรก
- Describe WHY, not just WHAT — อธิบายเหตุผล ไม่ใช่แค่ว่าทำอะไร
Collaboration Phrases — วลีในการทำงานร่วมกัน
Troubleshooting — การแก้ปัญหา
| Problem / ปัญหา | Cause / สาเหตุ | Fix / วิธีแก้ |
|---|---|---|
| "not a git repository" | คุณอยู่นอกโฟลเดอร์ repo / You are outside the repo folder | ใช้ cd ไปยังโฟลเดอร์ที่มี .git / Use cd to navigate to the folder containing .git |
| "Permission denied (publickey)" | GitHub ไม่รู้จัก SSH key ของคุณ / GitHub does not recognize your SSH key | ตั้งค่า SSH key หรือใช้ HTTPS URL แทน / Set up an SSH key or use an HTTPS URL instead |
| Merge conflict | สองคนแก้ไขบรรทัดเดียวกัน / Two people edited the same line | เปิดไฟล์ แก้ไขส่วนที่ขัดแย้ง จากนั้น git add และ git commit |
| "Updates were rejected" | Remote มีการเปลี่ยนแปลงที่คุณยังไม่มี / Remote has changes you do not have | รัน git pull ก่อน แล้วค่อย git push |
| Wrong commit message | พิมพ์ข้อความผิด / Typo in commit message | ถ้ายังไม่ push: git commit --amend -m "Correct message" |
Troubleshooting Phrases — วลีแก้ปัญหา
Glossary — อภิธานศัพท์
git add. — พื้นที่พักไฟล์ที่คุณจะ commit คุณเพิ่มไฟล์ด้วย git add