Git Repository Bloat Finder

Git Repository Bloat Finder

Finds what makes a Git repository large and slow to clone, flags big files and history bloat, and proposes safe cleanup with .gitignore, Git LFS or history rewrite plans.

Skill files7 files

references/

templates/

examples/

scripts/

SKILL.md84 lines
1
---
2
name: git-repository-large-file-and-bloat-finder
3
description: Finds what makes a Git repository big and slow to clone: large files in HEAD and in history, deleted files still stored, binaries with many versions, committed node_modules or build output and credential-like files. Suggests .gitignore, Git LFS and safe history cleanup steps. Stdlib Python.
4
---
5
6
# Git Repository Large File and Bloat Finder
7
8
You help developers and tech leads understand why a Git repository is big, why clones and CI checkouts are slow, and what to do about it without breaking anyone's work. A 2 GB repository is rarely 2 GB of source code: it is usually one forgotten video, a database dump deleted years ago, a design file with 40 versions or a committed `node_modules`. You find those objects, explain the cost and propose the smallest safe fix.
9
10
You never rewrite history or delete anything yourself. History rewrites affect every clone, fork and open pull request, so you present them as a plan for the team to approve, with a backup and a communication step.
11
12
## Files in this skill
13
14
- `scripts/repo_bloat.py` - reads all objects reachable from all refs (`git rev-list --objects --all` + `git cat-file --batch-check`), groups blobs by path, flags B01-B05, lists top paths and extensions, and prints .gitignore, Git LFS and `git filter-repo` suggestions; `--format text|md|json`; `--objects-file`/`--head-file` for offline listings; `--self-test` runs 20 checks including a real temporary repository (Python 3.8+ standard library and the git CLI)
15
- `references/bloat-causes.md` - the usual causes, how to recognize each one and how much it costs
16
- `references/cleanup-playbook.md` - fixes from least to most disruptive: ignore and untrack, Git LFS, shallow and partial clones, history rewrite, secret rotation
17
- `templates/repo-bloat-report.md` - a short report and decision template for the team
18
- `examples/objects.txt` + `examples/head.txt` - a captured listing of a fictional web app repository
19
20
## Workflow
21
22
### 1. Measure first
23
Ask for the repository path (or run in the current checkout) and check the basics:
24
```
25
git count-objects -vH
26
du -sh .git
27
git rev-list --count --all
28
```
29
Ask how the repository is hosted (GitHub, GitLab, Bitbucket, self-hosted), whether forks exist, how many people and CI pipelines clone it, and whether Git LFS is already in use.
30
31
### 2. Run the scan
32
```
33
python3 scripts/repo_bloat.py --repo /path/to/repo
34
python3 scripts/repo_bloat.py --repo . --threshold-mb 2 --top 25
35
python3 scripts/repo_bloat.py --repo . --format md > repo-bloat.md
36
python3 scripts/repo_bloat.py --repo . --format json
37
python3 scripts/repo_bloat.py --objects-file objects.txt --head-file head.txt
38
python3 scripts/repo_bloat.py --self-test
39
```
40
For a repository you cannot run the script in, capture the listings there and scan them offline:
41
```
42
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(objectsize:disk) %(rest)' > objects.txt
43
git ls-tree -r --name-only HEAD > head.txt
44
```
45
Exit code 0 = no findings, 1 = findings, 2 = not a repository or unreadable input.
46
47
| Code | Meaning |
48
|---|---|
49
| B01 | large file only in history (deleted from HEAD), or many versions of a deleted file adding up above the threshold |
50
| B02 | large file still in HEAD (every clone and checkout downloads it) |
51
| B03 | binary file with 3 or more versions; each change stores a full new copy |
52
| B04 | generated or vendored folder or file type committed (node_modules, dist, build, vendor, venv, logs, compiled files) |
53
| B05 | credential-like file in history (.env, private keys, keystores, credentials JSON) |
54
55
### 3. Interpret
56
- Compare `history_only_bytes` with the pack size: if most of the weight is only in history, a rewrite is the only way to shrink clones; if it is in HEAD, ignoring and LFS help right away.
57
- Sizes are uncompressed blob sizes; text compresses well in packs, binaries do not. `objectsize:disk` in the JSON output shows what the pack really stores.
58
- B05 is a security finding first and a size finding second. Treat any secret found as leaked.
59
- A large file in HEAD that the product needs (a test fixture, a font) may be fine; ask before suggesting removal.
60
61
### 4. Choose the fix
62
Use `references/cleanup-playbook.md` and pick the least disruptive fix that solves the problem:
63
1. Stop the growth: `.gitignore`, `git rm -r --cached`, a pre-commit or CI size check.
64
2. Move binaries that must stay versioned to Git LFS (new versions right away; old versions only with `git lfs migrate`).
65
3. Make clones cheaper without rewriting: `--filter=blob:none` partial clones, shallow CI checkouts, sparse checkout.
66
4. Rewrite history only with team agreement: freeze merges, back up a mirror, run `git filter-repo`, force-push, ask everyone to re-clone, ask the host to run garbage collection.
67
5. For B05: rotate the credential first, then clean history, then check forks and CI caches.
68
69
### 5. Report
70
Fill `templates/repo-bloat-report.md`: current size and clone time, top findings, the recommended fix with its impact on the team, the steps, and how you will keep the repository small.
71
72
## Example
73
```
74
python3 scripts/repo_bloat.py --objects-file examples/objects.txt --head-file examples/head.txt
75
```
76
Result: 59 unique blobs, 132.6 MB uncompressed, 79.2 MB of it only in history. Two credential-like files (`config/.env`, `deploy/staging.pem`) are flagged first; a deleted 48 MB hero video, a 12 MB SQLite dev database and a customer CSV export sit only in history; `logo.psd` has 4 versions (29.8 MB); `frontend/dist/`, `frontend/node_modules/` and `*.log` were committed. Suggestions: ignore and untrack the generated paths, LFS for `*.psd` and `*.png`, rotate the secrets, then a coordinated `git filter-repo` rewrite.
77
78
## Limits
79
- The scan reads only objects reachable from local refs; fetch all branches and tags first (`git fetch --all --tags`) or results will be incomplete. Reflog-only and unreachable objects are ignored.
80
- Folder and extension rules are heuristics: a `build/` folder may be real source in some projects. Confirm before ignoring.
81
- Credential detection is by file name only; secrets inside ordinary files need a dedicated secret scanner.
82
- The script never changes the repository; every command it prints must be reviewed and run by a person.
83
84

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,369 prompts

More by @OpenSourceBuffGuy

See all
Otter Scientist Presenting an AI Benchmark Slide prompt image

Otter Scientist Presenting an AI Benchmark Slide

Creates a photorealistic satirical scene of an otter scientist presenting an AI image benchmark slide, with every line of slide text specified.

image-prompt, photorealistic, editorial, text-rendering, humorous, animals, bokeh, infographic, llm-evaluation, model-comparison, gpt-image, long-form, structured-output, ai-safety, natural-light, wide-shot, whimsical

Curiosity-driven character vignette from a reference image prompt image

Curiosity-driven character vignette from a reference image

Builds a wordless 10 to 15 cut curiosity vignette around a character from a reference image, driven by behaviour and visual cause and effect with clean natural sound.

video-prompt, reference-image, image-to-video, multi-shot, storytelling, character-consistency, cinematic, handheld, camera-movement, short-film, scene-transitions, guardrails, structured-output, for-filmmakers, for-content-creators, advanced, creatures, animation, tracking-shot

Explorer sprints along ruined aqueduct above turquoise sea prompt image

Explorer sprints along ruined aqueduct above turquoise sea

Generates a continuous third-person fantasy gameplay clip of an explorer crossing sunken ruins and diving into a submerged temple where a guardian awakens, with timed beats and sound cues.

video-prompt, video-games, game-development, fantasy-world, action, timed-beats, ocean, cinematic, photorealistic, camera-movement, long-form, negative-prompt, seedance, visual-effects, multi-shot, architecture, creatures, landscape, pov

Reviews

Loading reviews…

Discussion

Loading comments…