0Pricing
Git Advanced: Monorepo, Submodules & Workflows · บทเรียน

การเพิ่มประสิทธิภาพคลัง Git

เรียนรู้เทคนิคต่าง ๆ เช่น การเก็บขยะ แฟ้มแพ็ก และโคลนแบบตื้น เพื่อปรับปรุงประสิทธิภาพและลดขนาดคลัง Git

การเพิ่มประสิทธิภาพคลัง Git เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Git Advanced: Monorepo, Submodules & Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Boost Your Git Performance

Ever noticed your Git repository getting slow? Large repositories, especially those with many files, long history, or binary assets, can become sluggish.

In this lesson, we'll learn how to optimize your Git repository's performance and reduce its size using techniques like garbage collection, pack files, and shallow clones.

Git's Object Storage

When you commit changes, Git stores your data as objects. Initially, these are stored as individual loose objects in the .git/objects directory.

While simple, storing many small loose objects can be inefficient, leading to increased disk space usage and slower operations as Git has to read many separate files.

Introducing Pack Files

To combat inefficiency, Git periodically groups these loose objects into pack files. A pack file is a single, compressed file that contains multiple Git objects.

This packing process uses delta compression, storing only the differences between similar objects, which significantly reduces disk space and speeds up data retrieval.

Automatic Garbage Collection

Git has a built-in mechanism called garbage collection (GC) that automatically runs in the background. It cleans up unnecessary objects and packs loose objects into pack files.

This automatic process usually happens after certain operations, like cloning, pulling, or committing a certain number of times, keeping your repository tidy without manual intervention.

Manual Garbage Collection: `git gc`

You can manually trigger garbage collection anytime using the git gc command. This is useful if you suspect your repository is bloated or if auto-GC hasn't run recently.

Running git gc will pack loose objects, remove unreachable objects, and optimize the repository's internal structure.

git gc

`git gc` with `--prune`

The --prune option with git gc allows you to specify how old unreachable objects must be before they are removed. By default, Git prunes objects older than 2 weeks.

You can use --prune=now to immediately remove all unreachable objects. Be careful, as this removes data that might still be recoverable via reflog if you prune too aggressively.

git gc --prune=now

Configuring GC Behavior

You can fine-tune Git's automatic garbage collection behavior using configuration settings. These are often set globally or per-repository.

  • gc.auto: Number of loose objects that trigger auto-GC.
  • gc.autopacklimit: Number of pack files that trigger auto-packing.

For example, to change the auto-GC threshold:

git config --global gc.auto 5000
# Default is 6700

Understanding Shallow Clones

For very large repositories, fetching the entire history can take a long time and consume significant disk space. A shallow clone helps with this.

A shallow clone downloads only a specified number of recent commits, rather than the complete history, making the initial clone operation much faster and the local repository much smaller.

Performing a Shallow Clone

To create a shallow clone, use the --depth option with git clone, specifying the number of commits you want to fetch.

This is extremely useful in CI/CD pipelines or when you only need to work on the latest version of a project without its entire history.

git clone --depth 1 https://github.com/user/repo.git

Deepening a Shallow Clone

What if you later need more history from a shallow clone? You can deepen it using git fetch --depth to retrieve additional commits.

This allows you to start shallow and progressively fetch more history only when needed, maintaining performance benefits.

git fetch --depth 50
# Fetches 50 more commits into history

Quick Check

Garbage collection and shallow clones are key for performance. Let's test your understanding.

Recap: Optimized Git

Great job! You've learned how to keep your Git repositories lean and fast.

  • Garbage Collection (GC) packs loose objects into efficient pack files.
  • You can run git gc manually or configure its automatic behavior.
  • Shallow clones (git clone --depth) speed up initial fetches by limiting history.
  • You can deepen a shallow clone with git fetch --depth.

These techniques are crucial for managing large projects and maintaining a smooth workflow.

คำถามที่พบบ่อย

บทเรียน “การเพิ่มประสิทธิภาพคลัง Git” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การเพิ่มประสิทธิภาพคลัง Git” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การเพิ่มประสิทธิภาพคลัง Git”

เรียนรู้เทคนิคต่าง ๆ เช่น การเก็บขยะ แฟ้มแพ็ก และโคลนแบบตื้น เพื่อปรับปรุงประสิทธิภาพและลดขนาดคลัง Git คุณปฏิบัติ Git Advanced: Monorepo, Submodules & Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Git Advanced: Monorepo, Submodules & Workflows หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Git Advanced: Monorepo, Submodules & Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การเพิ่มประสิทธิภาพคลัง Git” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Git Advanced: Monorepo, Submodules & Workflows นี้ได้ไหม

ได้ บทเรียน Git Advanced: Monorepo, Submodules & Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การกู้คืนคอมมิตและแขนงที่สูญหาย
  2. การแก้ไขข้อบกพร่องด้วย Git Bisect
  3. การเพิ่มประสิทธิภาพคลัง Git
  4. กู้คืองานด้วย Reflog และ Stash
← กลับไปที่ Git Advanced: Monorepo, Submodules & Workflows