Rewriting History with git filter-repo
Learn how to rewrite repository history at scale to remove large files or sensitive data using git filter-repo.
Rewriting History with git filter-repo is a free DevOps Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Rewrite History?
Sometimes you must rewrite the entire history of a repo: to remove a leaked password, delete huge accidentally-committed files, or fix author emails across all commits.
Meet git filter-repo
git filter-repo is the modern, fast tool for history rewriting. It replaces the old and slow git filter-branch.
Installing the Tool
It is a separate program, often installed via pip or a package manager.
pip install git-filter-repoAlways Work on a Clone
History rewriting is destructive. Operate on a fresh clone so you can throw it away if something goes wrong.
git clone --mirror git@github.com:you/repo.gitRemoving a File from History
To purge a file from every commit, use the --path and --invert-paths options.
git filter-repo --path secrets.env --invert-pathsRemoving Large Blobs
You can strip files above a size threshold to shrink a bloated repository.
git filter-repo --strip-blobs-bigger-than 10MRewriting Author Emails
Fix a wrong author email across all commits with a mailmap or callback.
git filter-repo --mailmap my-mailmap.txtReplacing Text in History
Scrub secret strings everywhere they appear using an expressions file.
git filter-repo --replace-text expressions.txtCommit Hashes Change
Rewriting history produces new commit hashes for everything affected. The repo's history diverges from any old copies.
Force Pushing the Result
After rewriting, you must force push because remote history no longer matches.
git push --force --allCoordinate with Your Team
Because everyone's clones are now stale, teammates must re-clone. Announce the rewrite to avoid resurrecting the removed data.
Quick Check
Test your understanding of history rewriting.
Recap
You learned to rewrite history:
git filter-reporeplaces filter-branch- Remove files, big blobs, or secret text from all history
- Always work on a clone; commit hashes change
- Force push and have the team re-clone afterward
Frequently asked questions
Is the “Rewriting History with git filter-repo” lesson free?
Yes — the full text of “Rewriting History with git filter-repo” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Rewriting History with git filter-repo”?
Learn how to rewrite repository history at scale to remove large files or sensitive data using git filter-repo. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Rewriting History with git filter-repo” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Git Reflog & Recovering History
- Git Bisect for Debugging
- Repository Maintenance & Housekeeping
- Rewriting History with git filter-repo