พื้นฐาน Git จากบรรทัดคำสั่ง
เรียนรู้คำสั่ง Git สำคัญสำหรับควบคุมเวอร์ชัน รวมถึงการคอมมิต การสร้างสาขา และการผสานสาขา
พื้นฐาน Git จากบรรทัดคำสั่ง เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Command Line Mastery และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What is Git?
Welcome to Git basics! Git is a powerful Version Control System (VCS). Think of it as a super-smart history book for your code.
It tracks every change you make, letting you revert to older versions, collaborate with others, and manage different features without stepping on toes. It's essential for modern software development!
Starting a Git Project
To begin tracking a project with Git, you first need to initialize a repository. This creates a special .git folder in your project, where Git stores all its tracking information.
Use the git init command in your project's root directory.
mkdir my_project
cd my_project
git initStaging Your Changes
Before saving your work, Git uses a 'staging area'. This is like a rough draft space where you select which changes you want to include in your next save.
The git add command is used to add files or changes to this staging area.
echo "My first line." > README.md
git add README.mdSaving Your Work (Commit)
Once changes are staged, you 'commit' them. A commit is a snapshot of your project at a specific point in time, with a descriptive message.
Use git commit -m "Your message" to save staged changes to your repository's history.
git commit -m "Initial commit: Added README.md"Viewing Project History
Git keeps a detailed log of all your commits. You can review this history to see who made what changes and when.
The git log command displays your repository's commit history. The --oneline option provides a concise view.
git log --onelineParallel Development with Branches
Branches are a core concept in Git. They allow you to diverge from the main line of development and continue working without affecting the main project.
- Work on new features.
- Fix bugs without breaking stable code.
- Experiment with new ideas.
The main (or master) branch is typically the stable version.
Creating a New Branch
To start a new line of development, you create a new branch. This doesn't move you to the new branch yet; it just creates it.
The git branch <branch-name> command creates a new branch. You can list all branches with just git branch.
git branch feature/login
git branchSwitching Between Branches
After creating a branch, you need to switch to it to start working on that specific line of development. Your files will reflect the state of that branch.
Use git switch <branch-name> to move to an existing branch. It's the modern way to navigate branches.
git switch feature/login
# Now you are on the 'feature/login' branchMerging Branches
Once you've finished work on a feature branch, you'll want to integrate those changes back into your main development line, usually the main branch.
First, switch to the target branch (e.g., main), then use git merge <source-branch> to bring in the changes.
git switch main
git merge feature/loginGit Workflow Check
You've learned the core steps for managing changes with Git. Let's test your understanding of how to save your work.
Git Basics Summary
Great job! You've learned the fundamental Git commands:
git init: To start a new repository.git add: To stage changes for a commit.git commit: To save staged changes to history.git log: To view your project's commit history.git branch: To create and list branches.git switch: To move between branches.git merge: To combine changes from different branches.
These commands form the backbone of managing your code with Git!
คำถามที่พบบ่อย
บทเรียน “พื้นฐาน Git จากบรรทัดคำสั่ง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “พื้นฐาน Git จากบรรทัดคำสั่ง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “พื้นฐาน Git จากบรรทัดคำสั่ง”
เรียนรู้คำสั่ง Git สำคัญสำหรับควบคุมเวอร์ชัน รวมถึงการคอมมิต การสร้างสาขา และการผสานสาขา คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “พื้นฐาน Git จากบรรทัดคำสั่ง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม
ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- พื้นฐาน Git จากบรรทัดคำสั่ง
- ตัวแปรสภาพแวดล้อมและนามแฝง
- การกำหนดค่าเชลล์: `.bashrc`, `.zshrc`, `.profile`
- การแตกแขนงและผสานด้วย Git จากบรรทัดคำสั่ง