Skip to content

Commit 50baf30

Browse files
committed
docs(notes): add Git garbage collection explanation
1 parent 8915b69 commit 50baf30

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

_posts/en/2025-01-11-notes-en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ generated: false
77
translated: false
88
---
99

10-
These 2128 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
10+
These 2129 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
1111

1212
* [AI Model Context Window Capacities](/notes/2025-09-03-ai-model-context-window-en)
1313
* [Alphabet Hits $186.66B in H1 2025](/notes/2025-09-03-alphabet-h1-2025-revenue-en)
@@ -18,6 +18,7 @@ These 2128 notes are primarily generated by AI chatbots. I used them to summariz
1818
* [Upgrade Claude Code Quickly Now](/notes/2025-09-03-claudecode-upgrade-quick-en)
1919
* [DBS H1 2025 Record Revenue Workforce Cuts](/notes/2025-09-03-dbs-h1-2025-revenue-cuts-en)
2020
* [Discipline Versus Speed Career Bets](/notes/2025-09-03-discipline-vs-speed-bets-en)
21+
* [Git Garbage Collection Explained](/notes/2025-09-03-git-garbage-collection-en)
2122
* [HSBC H1 2025 Revenue Drops but Grows Adjusted](/notes/2025-09-03-hsbc-h1-2025-revenue-en)
2223
* [Configuring JaCoCo Agent Output Directory](/notes/2025-09-03-jaccode-output-dir-en)
2324
* [JaCoCo Destfile Usage and Analysis](/notes/2025-09-03-jacoco-destfile-analysis-en)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Git Garbage Collection Explained
3+
lang: en
4+
layout: post
5+
audio: false
6+
translated: false
7+
generated: true
8+
image: false
9+
---
10+
11+
`git gc` stands for **Git garbage collection**. It’s a housekeeping command that cleans up and optimizes your local repository.
12+
13+
### What it does
14+
15+
* **Compresses file history**: Git stores objects (commits, trees, blobs) in a database. Over time, many loose objects accumulate. `git gc` packs them together into a compact binary file, saving disk space.
16+
* **Removes unreachable objects**: If you deleted branches or rebased, some commits may no longer be reachable from any reference. Git keeps them for safety, but `git gc` eventually cleans them up.
17+
* **Optimizes references**: It rewrites and packs refs like tags and branches to make lookups faster.
18+
* **Prunes reflogs**: Old reflog entries (records of HEAD changes) beyond the expiry period get removed.
19+
20+
### Why it sometimes happens automatically
21+
22+
* Git runs **automatic background `gc`** when the number of loose objects or pack files crosses a threshold. For example, if you’ve made a lot of commits, rebases, or merges, Git may trigger it.
23+
* Many Git commands (like `git fetch`, `git merge`, or `git rebase`) check whether a `gc` is advisable and run it automatically if needed.
24+
* This helps keep your repo performant without you having to think about it.
25+
26+
### When to run it manually
27+
28+
* If your repository feels **slow** or **bloated** (e.g., large `.git` folder).
29+
* After doing a **big cleanup** (like deleting branches or removing large files from history).
30+
* If you want to force immediate cleanup:
31+
32+
```bash
33+
git gc --prune=now --aggressive
34+
```
35+
36+
*(be careful: `--aggressive` can take a long time, especially on large repos)*
37+
38+
---
39+
40+
Do you want me to also explain how to **check when Git last ran `gc` automatically** and what thresholds trigger it?

original/2025-01-11-notes-en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ generated: false
77
translated: false
88
---
99

10-
These 2128 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
10+
These 2129 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
1111

1212
* [AI Model Context Window Capacities](/notes/2025-09-03-ai-model-context-window-en)
1313
* [Alphabet Hits $186.66B in H1 2025](/notes/2025-09-03-alphabet-h1-2025-revenue-en)
@@ -18,6 +18,7 @@ These 2128 notes are primarily generated by AI chatbots. I used them to summariz
1818
* [Upgrade Claude Code Quickly Now](/notes/2025-09-03-claudecode-upgrade-quick-en)
1919
* [DBS H1 2025 Record Revenue Workforce Cuts](/notes/2025-09-03-dbs-h1-2025-revenue-cuts-en)
2020
* [Discipline Versus Speed Career Bets](/notes/2025-09-03-discipline-vs-speed-bets-en)
21+
* [Git Garbage Collection Explained](/notes/2025-09-03-git-garbage-collection-en)
2122
* [HSBC H1 2025 Revenue Drops but Grows Adjusted](/notes/2025-09-03-hsbc-h1-2025-revenue-en)
2223
* [Configuring JaCoCo Agent Output Directory](/notes/2025-09-03-jaccode-output-dir-en)
2324
* [JaCoCo Destfile Usage and Analysis](/notes/2025-09-03-jacoco-destfile-analysis-en)

0 commit comments

Comments
 (0)