Interview Prep/Git & GitHub/Rebase, Cherry-pick and History Rewriting

The repo is slow to clone because someone committed a 1 GB dataset two years ago and deleted it later. How do you shrink it?

IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Deleting a file in a later commit leaves it in history forever.

What I'd do →

  1. Find big blobs: git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sort -k3 -n -r | head.
  2. On a fresh mirror clone: git filter-repo --path data/big.csv --invert-paths.
  3. Force-push all refs, then have everyone re-clone.
  4. Ask GitHub Support to run garbage collection on cached views if needed.

Why → Only rewriting history removes the blob, and that changes SHAs for everything after it.

Interview tip → Plan the re-clone communication. Open PRs will have to be recreated.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting