Introduction to Git
เริ่มต้นใช้งาน Git

Learn version control — track changes, collaborate, and never lose your work again

เรียนรู้การจัดการเวอร์ชัน — ติดตามการเปลี่ยนแปลง ทำงานร่วมกัน และไม่มีวันสูญเสียงานอีกต่อไป

What Is Git? — Git คืออะไร?

🇹🇭 ภาษาไทย

Git คือโปรแกรมที่ช่วยให้คุณติดตามการเปลี่ยนแปลงในไฟล์ต่างๆ ลองนึกภาพมันเหมือน "การบันทึกเกม" สำหรับโค้ดของคุณ คุณสามารถ save points ดู history ของการเปลี่ยนแปลง และกลับไปยังเวอร์ชันก่อนหน้าได้ตลอดเวลา นักพัฒนาทั่วโลกใช้ 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 — วลีที่มีประโยชน์

"I use Git to track all my code changes."— "ฉันใช้ Git เพื่อติดตามการเปลี่ยนแปลงโค้ดทั้งหมด"
"Can you share the repository link with me?"— "คุณช่วยส่งลิงก์ repository ให้ฉันได้ไหม?"
"I pushed the latest changes to GitHub."— "ฉัน push การเปลี่ยนแปลงล่าสุดขึ้น GitHub แล้ว"

What You Need — สิ่งที่ต้องมี

🇹🇭 ภาษาไทย

ก่อนเริ่มต้น คุณต้องติดตั้งและตั้งค่าสิ่งเหล่านี้:

🇬🇧 English

Before you start, you need to install and configure these things:

Git
กิต / โปรแกรมจัดการเวอร์ชัน
ดาวน์โหลดฟรีจาก git-scm.com รองรับ Windows, Mac, Linux
Free download from git-scm.com. Works on Windows, Mac, and Linux.
Terminal
เทอร์มินัล / โปรแกรมบรรทัดคำสั่ง
บน Windows: ใช้ Git Bash (ติดตั้งพร้อม Git) หรือ PowerShell. บน Mac/Linux: ใช้ Terminal
Windows: Git Bash comes with Git. Mac/Linux: use the built-in Terminal.
GitHub Account (Optional)
บัญชี GitHub (ไม่จำเป็นสำหรับการเรียนรู้เบื้องต้น)
สมัครฟรีที่ github.com ใช้สำหรับเก็บโค้ดออนไลน์และทำงานร่วมกับผู้อื่น
Sign up free at github.com — needed for remote collaboration.
Code Editor
โปรแกรมแก้ไขโค้ด
แนะนำ VS Code (ฟรี) ซึ่งมีส่วนเสริม Git ในตัว ทำให้จัดการ Git ได้ง่ายขึ้น
VS Code (free) is recommended — it has built-in Git support.

Part 1: Core Concepts — แนวคิดหลัก

1 Repository — ที่เก็บโค้ด

🇹🇭 ภาษาไทย

A repository (หรือ "repo") คือโฟลเดอร์ที่ Git ดูแล — มันเก็บไฟล์ทั้งหมดและประวัติการเปลี่ยนแปลงทั้งหมดของคุณ ทุกโปรเจกต์มี repo ของตัวเอง

มีสองประเภท: 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 commit คือการ "บันทึก" ของ Git — มันบันทึกสถานะไฟล์ในขณะนั้น พร้อมกับข้อความอธิบายว่าคุณเปลี่ยนแปลงอะไร เปรียบเหมือนกับ checkpoint ในเกม แต่ละ commit มี ID เฉพาะตัว

🇬🇧 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 branch คือเส้นทางการพัฒนาที่แยกออกมา คุณสามารถทดลองสิ่งใหม่บน branch ได้โดยไม่กระทบกับโค้ดหลัก (main branch) เมื่อพร้อมก็ merge กลับเข้าไป

🇬🇧 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 — ส่งขึ้นและดึงลง

🇹🇭 ภาษาไทย

Push คือการส่ง commit จาก local repo ไปยัง remote repo (เช่น GitHub)
Pull คือการดึงการเปลี่ยนแปลงล่าสุดจาก remote repo มายัง local repo ของคุณ
คำสั่งเหล่านี้ทำให้ local และ remote in sync เสมอ

🇬🇧 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

"I'll create a new branch for this feature."— "ฉันจะสร้าง branch ใหม่สำหรับฟีเจอร์นี้"
"Please pull the latest changes before you start."— "กรุณา pull การเปลี่ยนแปลงล่าสุดก่อนเริ่มงาน"
"I committed my changes with a clear message."— "ฉัน commit การเปลี่ยนแปลงพร้อมข้อความที่ชัดเจน"
"The merge conflict needs to be resolved."— "ต้องแก้ไข merge conflict ก่อน"

Part 2: Essential Commands — คำสั่งสำคัญ

🇹🇭 ภาษาไทย

คำสั่ง Git ทั้งหมดเริ่มต้นด้วยคำว่า git แล้วตามด้วยคำสั่งย่อย เช่น git commit หรือ git push คุณพิมพ์คำสั่งเหล่านี้ใน terminal

🇬🇧 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:

# Tell Git your name and email (used in commit history) git config --global user.name "Your Name" git config --global user.email "you@example.com" # Verify your settings git config --list

2 Starting a Repository — เริ่มต้น Repository

🇹🇭 ภาษาไทย

มีสองวิธีในการเริ่มต้น: สร้าง repo ใหม่บนคอมพิวเตอร์ของคุณ หรือ clone repo ที่มีอยู่แล้วจาก remote

🇬🇧 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.

# Method 1: Create a new repo in the current folder git init # Method 2: Clone an existing repo from GitHub git clone https://github.com/username/repo-name.git

3 The Basic Workflow — ขั้นตอนการทำงานพื้นฐาน

🇹🇭 ภาษาไทย

วงจรการทำงานปกติกับ Git มีสามขั้นตอนหลัก: stagecommitpush

  1. แก้ไขหรือสร้างไฟล์
  2. เพิ่มไฟล์เข้า staging area ด้วย git add
  3. บันทึกการเปลี่ยนแปลงด้วย git commit
  4. ส่งขึ้น remote ด้วย git push

🇬🇧 English

The regular Git workflow has three main steps: stagecommitpush.

  1. Edit or create files
  2. Add files to the staging area with git add
  3. Save a snapshot with git commit
  4. Send to remote with git push
# Check what has changed (always start here) git status # Stage specific files for commit git add filename.html # Stage ALL changed files at once git add . # Commit with a descriptive message git commit -m "Add homepage with bilingual content" # Push to remote (first time, set the upstream) git push -u origin main # Push after upstream is set git push

4 Working with Branches — ทำงานกับ Branch

🇹🇭 ภาษาไทย

ทำงานบน branch ใหม่เสมอเมื่อพัฒนาฟีเจอร์ใหม่ ไม่ควรทำงานโดยตรงบน main 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.

# List all local branches (* = current branch) git branch # Create a new branch git branch feature/my-new-feature # Switch to a branch git checkout feature/my-new-feature # Create AND switch in one step (shortcut) git checkout -b feature/my-new-feature # Merge a branch back into main git checkout main git merge feature/my-new-feature

5 Viewing History — ดูประวัติ

🇹🇭 ภาษาไทย

คำสั่ง git log แสดงประวัติ commit ทั้งหมด และ git diff แสดงสิ่งที่เปลี่ยนแปลงในแต่ละ file

🇬🇧 English

The git log command shows the full commit history. git diff shows exactly what changed in each file.

# Show full commit history git log # Show compact one-line history git log --oneline # Show what changed (unstaged changes) git diff # Show what changed (staged changes ready to commit) git diff --staged

🎉 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 — วลีในกระบวนการทำงาน

"Did you already push your changes?"— "คุณ push การเปลี่ยนแปลงแล้วหรือยัง?"
"I need to pull before I start working."— "ฉันต้อง pull ก่อนเริ่มทำงาน"
"Always write a clear commit message."— "เขียนข้อความ commit ที่ชัดเจนเสมอ"
"I'll review your pull request tomorrow."— "ฉันจะรีวิว pull request ของคุณพรุ่งนี้"

Part 3: GitHub & Collaboration — ทำงานร่วมกันบน GitHub

🇹🇭 ภาษาไทย

GitHub คือเว็บไซต์ที่เก็บ Git repositories ออนไลน์ ทำให้คุณสามารถ collaborate กับนักพัฒนาคนอื่นได้ทั่วโลก มันฟรีสำหรับโปรเจกต์สาธารณะ

🇬🇧 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

🇹🇭 ภาษาไทย

Fork คือการคัดลอก repo ของคนอื่นมาไว้ใน GitHub ของคุณ จากนั้นคุณสามารถ 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.

# After forking on GitHub, clone to your computer git clone https://github.com/YOUR-USERNAME/forked-repo.git # Add the original repo as "upstream" to get future updates git remote add upstream https://github.com/ORIGINAL-OWNER/repo.git # Pull updates from the original repo git pull upstream main

2 Pull Request — การขอ merge โค้ด

🇹🇭 ภาษาไทย

A pull request (PR) คือการขออนุมัติให้ merge โค้ดของคุณเข้าไปใน repo หลัก เจ้าของโปรเจกต์จะ review โค้ดของคุณก่อนที่จะ merge

🇬🇧 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 — วลีในการทำงานร่วมกัน

"I opened a pull request for your review."— "ฉันเปิด pull request รอการ review ของคุณแล้ว"
"There is a merge conflict we need to fix."— "มี merge conflict ที่เราต้องแก้ไข"
"I will fork the repo and submit a patch."— "ฉันจะ fork repo และส่ง patch ไป"

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 — วลีแก้ปัญหา

"I have a merge conflict — can you help me?"— "ฉันมี merge conflict — ช่วยฉันได้ไหม?"
"My push was rejected. I need to pull first."— "การ push ถูกปฏิเสธ ฉันต้อง pull ก่อน"
"I accidentally committed to the wrong branch."— "ฉัน commit ไปยัง branch ผิดโดยไม่ตั้งใจ"
"Let me check the git log to find the issue."— "ขอดู git log เพื่อหาต้นตอของปัญหา"

Glossary — อภิธานศัพท์

Repository
รีโพซิทอรี / ที่เก็บโค้ด
A folder managed by Git containing all project files and their complete change history. — โฟลเดอร์ที่ Git ดูแล เก็บไฟล์โปรเจกต์ทั้งหมดและประวัติการเปลี่ยนแปลงทั้งหมด
Commit
คอมมิต / การบันทึกการเปลี่ยนแปลง
A saved snapshot of your files at a specific point in time, with a message describing the change. — ภาพถ่ายไฟล์ในช่วงเวลาหนึ่ง พร้อมข้อความอธิบายการเปลี่ยนแปลง
Branch
แบรนช์ / สาขา
A separate line of development in a repository. Lets you work on features without affecting the main codebase. — เส้นทางการพัฒนาแยกออกมา ให้คุณทำงานบนฟีเจอร์โดยไม่กระทบโค้ดหลัก
Merge
เมิร์จ / รวมโค้ด
Combining changes from one branch into another. Usually used to bring a feature branch back into main. — การรวมการเปลี่ยนแปลงจาก branch หนึ่งเข้าไปในอีก branch
Clone
โคลน / คัดลอก repo ลงเครื่อง
Downloading a complete copy of a remote repository to your local computer. — การดาวน์โหลดสำเนา repo ทั้งหมดจาก remote มาไว้บนคอมพิวเตอร์ของคุณ
Push
พุช / ส่งขึ้น remote
Uploading your local commits to a remote repository (e.g., GitHub). — การอัปโหลด commit ของคุณจาก local ขึ้นไปยัง remote repository
Pull
พูล / ดึงลงจาก remote
Downloading the latest commits from a remote repository to your local machine. — การดาวน์โหลด commit ล่าสุดจาก remote มายัง local ของคุณ
Diff
ดิฟ / ความแตกต่าง
The differences between two versions of a file or between the current state and the last commit. — ความแตกต่างระหว่างสองเวอร์ชันของไฟล์ หรือระหว่างสถานะปัจจุบันกับ commit ล่าสุด
Staging Area
พื้นที่เตรียม commit
A holding area where you place file changes before committing them. Files are staged with git add. — พื้นที่พักไฟล์ที่คุณจะ commit คุณเพิ่มไฟล์ด้วย git add
Remote
รีโมต / repo บนเซิร์ฟเวอร์
A version of your repository hosted on a server (like GitHub or GitLab) that others can access. — เวอร์ชันของ repo ที่โฮสต์บนเซิร์ฟเวอร์ เช่น GitHub ที่ผู้อื่นเข้าถึงได้
Fork
ฟอร์ก / คัดลอก repo ของคนอื่น
A personal copy of someone else's repository on GitHub. Lets you experiment without affecting the original. — สำเนาส่วนตัวของ repo คนอื่นบน GitHub ให้คุณทดลองโดยไม่กระทบต้นฉบับ
Pull Request
พูลรีเควสต์ / การขอ merge โค้ด
A GitHub feature to propose merging your changes into another repository. The owner reviews and approves or rejects. — ฟีเจอร์ GitHub สำหรับขอ merge การเปลี่ยนแปลงของคุณเข้า repo อื่น เจ้าของ review และอนุมัติหรือปฏิเสธ
Merge Conflict
ความขัดแย้งตอน merge
When two branches change the same part of the same file, Git cannot automatically merge them and needs your help. — เมื่อสอง branch เปลี่ยนแปลงส่วนเดียวกันของไฟล์เดียวกัน Git ไม่สามารถ merge อัตโนมัติได้
git log
คำสั่งดูประวัติ commit
A Git command that shows the complete history of commits in the current repository. — คำสั่ง Git ที่แสดงประวัติ commit ทั้งหมดใน repository ปัจจุบัน
git status
คำสั่งตรวจสอบสถานะ
Shows which files have been changed, staged, or are untracked. Run this before every commit. — แสดงไฟล์ที่เปลี่ยนแปลง staged หรือยังไม่ถูกติดตาม รันก่อน commit เสมอ
Version Control
การจัดการเวอร์ชัน
A system that records changes to files over time so you can recall specific versions. Git is the most popular version control system. — ระบบที่บันทึกการเปลี่ยนแปลงไฟล์ตลอดเวลา เพื่อให้คุณเรียกดูเวอร์ชันเฉพาะได้

Quick Reference Checklist — รายการตรวจสอบ

🇹🇭 ภาษาไทย — คุณทำได้แล้วหรือยัง?







🇬🇧 English — Can You Do This?