Mervia AcademyLearn
เวิร์กช็อป Git 10xGit 10x Workshop

Git 102: สร้าง repo และอ่าน statusGit 102: create a repo and read status

สร้าง Git repository เล็กๆ เข้าใจ git init และใช้ git status อ่านไฟล์ untracked, modified และ stagedCreate a small Git repository, understand git init, and use git status to read untracked, modified, and staged files.

The first Git habit is not committing.

The first habit is checking where you are.

git status

git status tells you the state of your working tree and staging area. It is the dashboard.

Check Git is installed

In Terminal or PowerShell:

git --version

If Git is installed, you will see a version number.

If it is not installed yet, install Git using the official installer for your operating system, then come back.

Create a practice folder

Use a folder that contains no private work.

mkdir git-10x-practice
cd git-10x-practice

Now create a small file:

echo "# Git 10x Practice" > README.md

On Windows PowerShell, this command also works.

Initialize the repository

Turn the folder into a Git repository:

git init

Git creates a hidden .git folder. That folder stores repository history and metadata.

Do not edit .git by hand.

Read the first status

Run:

git status

You should see that README.md is untracked.

Untracked means:

This file exists in the folder, but Git has not been told to include it in history yet.

Three common states

You will see these states often.

StateMeaning
untrackedGit sees a new file but is not tracking it
modifiedGit tracks the file and it changed
stagedthe change is selected for the next commit

git status tells you which state each file is in and often suggests the next command.

Add a gitignore early

A .gitignore file tells Git which files should not be tracked.

Create one:

echo ".env" > .gitignore
echo "node_modules/" >> .gitignore

This is not complete for every project, but it shows the idea.

Common things to ignore:

  • .env
  • dependency folders like node_modules/
  • build output
  • OS noise files
  • logs

If you already committed a secret, .gitignore will not remove it from history. Rotate the secret and ask for help.

Practice: status reading

Run:

git status

Write down:

Current branch:

Untracked files:

Modified files:

Staged files:

What command is Git suggesting?

Do not commit yet. The next lesson covers diff, staging, and the first commit.

Next: Git 103 - diff, add, commit, log.

นิสัยแรกของ Git ไม่ใช่การ commit

นิสัยแรกคือเช็กว่าตอนนี้เราอยู่ในสภาพไหน

git status

git status บอกสถานะของ working tree และ staging area มันคือ dashboard ของ Git

เช็กว่าเครื่องมี Git แล้วหรือยัง

ใน Terminal หรือ PowerShell:

git --version

ถ้ามี Git แล้ว จะเห็นเลข version

ถ้ายังไม่มี ให้ install Git จาก installer ทางการของระบบปฏิบัติการที่ใช้ แล้วค่อยกลับมาต่อ

สร้าง folder ฝึก

ใช้ folder ที่ไม่มีงาน private

mkdir git-10x-practice
cd git-10x-practice

จากนั้นสร้างไฟล์เล็กๆ:

echo "# Git 10x Practice" > README.md

บน Windows PowerShell command นี้ใช้ได้เหมือนกัน

เริ่ม repository

เปลี่ยน folder นี้ให้เป็น Git repository:

git init

Git จะสร้าง folder ซ่อนชื่อ .git ไว้เก็บ history และ metadata ของ repository

อย่าแก้ .git ด้วยมือ

อ่าน status แรก

รัน:

git status

ควรเห็นว่า README.md เป็น untracked

untracked แปลว่า:

ไฟล์นี้อยู่ใน folder แล้ว แต่ Git ยังไม่ได้ถูกสั่งให้เก็บไว้ใน history

สถานะที่เจอบ่อย 3 แบบ

คุณจะเจอสามสถานะนี้บ่อย:

สถานะความหมาย
untrackedGit เห็นไฟล์ใหม่ แต่ยังไม่ track
modifiedGit track ไฟล์นี้อยู่ และไฟล์เปลี่ยน
stagedchange นี้ถูกเลือกไว้สำหรับ commit ถัดไป

git status จะบอกว่าไฟล์อยู่สถานะไหน และมักแนะนำ command ถัดไป

เพิ่ม gitignore ตั้งแต่ต้น

ไฟล์ .gitignore บอก Git ว่าไฟล์แบบไหนไม่ควรถูก track

สร้างไฟล์นี้:

echo ".env" > .gitignore
echo "node_modules/" >> .gitignore

นี่ไม่ใช่รายการที่ครบทุก project แต่พอให้เห็นไอเดีย

สิ่งที่มัก ignore:

  • .env
  • folder dependency เช่น node_modules/
  • build output
  • ไฟล์ noise จากระบบปฏิบัติการ
  • log

ถ้า commit secret ไปแล้ว .gitignore จะไม่ลบมันออกจาก history ให้ rotate secret และขอความช่วยเหลือ

แบบฝึก: อ่าน status

รัน:

git status

จด:

Branch ปัจจุบัน:

ไฟล์ untracked:

ไฟล์ modified:

ไฟล์ staged:

Git แนะนำ command อะไร?

ยังไม่ต้อง commit บทถัดไปจะเรียน diff, staging และ commit แรก

บทถัดไป: Git 103 - diff, add, commit, log

เข้าสู่ระบบเพื่อบันทึกความคืบหน้าSign in to track your progress

เข้าสู่ระบบSign in