Skip to main content

Git Repository Cleanup and Optimization

Audit and optimize a bloated Git repo: strip large files from history, prune stale branches, migrate to LFS, and cut clone times.

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

What this prompt does

This prompt audits and optimizes a bloated Git repository that has grown to [repo_size] with [branch_count] branches. It produces commands to find large files in history using git-filter-repo, a script to safely delete merged branches older than [stale_branch_age], steps to squash old history while preserving the recent [keep_months] months, and a .gitignore audit for [language] projects. It also covers a Git LFS migration plan for your [large_file_types] and CI-friendly shallow clone and sparse checkout configs.

The structure works because it pairs aggressive cleanup with strict safety. History rewrites with git-filter-repo are unforgiving once they touch shared history, so the prompt insists on dry-run options and safety checks for every destructive operation. By adding pre-commit hooks to block future large-file commits, it not only slims the repo today but stops it from ballooning again from committed binaries and dead branches. It also addresses CI clone times directly with shallow clone and sparse checkout configurations, which is often where bloat hurts most: every pipeline run pays the cost of a fat history. The combination of a one-time cleanup and ongoing guardrails is what keeps the repo lean instead of slipping back to [repo_size] a year later.

When to use it

  • Clone times are crawling because the repo has grown to [repo_size] from committed binaries.
  • You have [branch_count] branches and need to safely prune ones merged over [stale_branch_age] ago.
  • You want to move [large_file_types] into Git LFS instead of bloating history.
  • Your CI is slow and could benefit from shallow clones or sparse checkout.
  • You need a .gitignore audit so the same [language] build artifacts stop getting committed.
  • You want pre-commit hooks that block large files before they ever enter history.

Example output

Expect a cleanup playbook: git-filter-repo commands to locate and strip large files, a branch-pruning script honoring [stale_branch_age], history-squash steps that keep the last [keep_months] months, a .gitignore audit for [language], an LFS migration plan for [large_file_types], and CI shallow-clone/sparse-checkout configs. Every destructive step is presented with dry-run options and safety checks so you can preview before committing.

Pro tips

  • Always run history rewrites with the provided dry-run flags first and take a full backup, because git-filter-repo cannot be undone once it touches shared history.
  • Coordinate with your team before rewriting history, since everyone must re-clone afterward and stale forks will conflict.
  • Be specific about [large_file_types] so the LFS migration targets the right binaries instead of sweeping in source files.
  • Set [keep_months] to a window that preserves meaningful blame and bisect history, not just the last few weeks.
  • Tune [stale_branch_age] conservatively at first so you do not delete branches someone is quietly still using.
  • Iterate by running the large-file report, reviewing the candidates, and only then applying the rewrite.

Frequently Asked Questions

Is rewriting Git history with this safe?
It can be safe if you follow the precautions, but it is inherently risky. The prompt provides dry-run options and safety checks, and you should take a full backup and coordinate with your team first. Once git-filter-repo touches shared history, everyone must re-clone and old references break, so never rush it.
Will my teammates need to re-clone after cleanup?
Yes, if you rewrite history. Stripping large files or squashing old commits changes commit hashes, so existing clones and forks diverge from the new history. Plan the rewrite for a coordinated window, notify everyone, and have them re-clone afterward to avoid accidentally pushing the old history back.
What does the Git LFS migration actually move?
It targets the `[large_file_types]` you specify, such as images, videos, and compiled binaries, moving them out of regular history and into LFS storage. Be precise with that variable so source files are not swept in. LFS reduces clone size, but it adds an LFS dependency your tooling and CI must support.
How do the pre-commit hooks prevent future bloat?
They check staged files against size or type rules before a commit lands, blocking accidental large-file commits at the source. Combined with a cleaned-up `.gitignore` for your `[language]`, this stops the repo from re-bloating. The hooks run locally, so the team needs them installed for the protection to be consistent.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Mehr in Git & GitHub Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support