Git History Rewrite at Scale: Removing 100MB+ Files Safely

Introduction

Large files inside Git repositories are a silent problem. They increase clone times, inflate repository size, and in platforms like Bitbucket Cloud, can completely block pushes once files exceed 100MB.

During a migration exercise, we encountered multiple repositories containing large binary files embedded directly in Git history. Some were intentionally added during testing; others were legacy artifacts. Regardless of origin, the impact was the same: repository growth, push failures, and migration risk.

We needed a scalable, production-safe solution to:

  • Identify files larger than 100MB
  • Preserve those files safely
  • Remove them from Git history
  • Maintain traceability
  • Avoid Git LFS
  • Process multiple repositories in batch

This article explains the approach, implementation, and verification process.

The Problem with Large Files in Git

Git is optimized for source code, not large binaries. When a file larger than 100MB is committed:

  • It becomes part of Git object history.
  • Even if later deleted, the blob remains in history.
  • Every clone downloads that blob.
  • Bitbucket Cloud blocks pushes containing files ≥100MB.
  • Repository size increases permanently unless history is rewritten.

Deleting the file in a new commit is not enough. The blob must be removed from the entire commit graph.

Are you ready for limitless expansion? Take advantage of seamless cloud migration services designed to accelerate your business growth today.

Requirements

We defined clear technical requirements:

  1. Scan multiple repositories under a parent directory.
  2. Detect files larger than 100MB in:
    • Working directory
    • Full Git history
  3. Generate a detailed CSV audit report.
  4. Back up repositories before modification.
  5. Archive large blobs to S3 before removal.
  6. Rewrite Git history safely.
  7. Force push cleaned repositories.
  8. Verify that no large blobs remain.

Architecture Overview

The cleanup workflow followed this structure:

Implementation Strategy

1. Repository Discovery

All repositories were discovered under a specified parent directory by locating .git folders. This allowed batch processing without hardcoding repository names.

2. Scanning Git History

To detect large blobs in history, we relied on Git’s object database:

git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'

We filtered for blobs larger than 100MB (104857600 bytes). This approach ensures that even deleted historical files are detected.

3. CSV Report Generation

For traceability, a consolidated CSV report was generated containing:

  • Repository name
  • File path
  • File size (bytes + human-readable)
  • Blob hash
  • Commit hash
  • Target S3 path

This report served as:

  • A dry-run validation artifact
  • An audit record
  • A mapping between Git history and S3 storage

4. S3 Archival Before Deletion

Before rewriting history, large blobs were extracted using:

git cat-file -p <blob-hash>

They were uploaded to S3 using a structured path:

s3://<bucket>/<repo-name>/<commit-hash>/<file-name>

This ensured:

  • No data loss
  • Full traceability
  • Commit-level mapping
  • Easy retrieval if required

5. Safe History Rewrite

We used git-filter-repo, which is the modern, recommended alternative to git filter-branch.

For each repository:

  • Paths to remove were collected from the CSV report.
  • git-filter-repo --invert-paths was used to remove those paths from all commits.
  • A full backup tarball was created before execution.
  • A confirmation prompt prevented accidental execution.

This resulted in a new, clean commit graph with large blobs removed.

6. Force Push and Remote Restoration

Since history was rewritten:

  • All commit hashes changed.
  • A force push was required.
  • Team members were instructed to re-clone repositories.

Remote URLs were preserved or restored automatically to ensure push continuity.

Verification Method

Cleanup was verified using a direct scan of Git objects:

git rev-list--objects--all \
|git cat-file--batch-check='%(objecttype) %(objectname) %(objectsize)' \
|awk'$1 == "blob" && $3 >= 104857600'

If the command returned no output, it confirmed:

  • No blob ≥100MB remained
  • History rewrite was successful
  • Repository was safe to push and clone

This verification step is critical and should never be skipped.

Results

  • 10 repositories processed
  • ~3GB of large blobs identified
  • All large files archived to S3
  • Git history rewritten safely
  • Force push completed
  • No remaining blobs ≥100MB in any repository
  • Repositories ready for clean migration

Lessons Learned

  1. Deleting files in a commit does not remove them from history.
  2. Always run a dry-run before destructive operations.
  3. Always create a full backup before rewriting history.
  4. Always verify using Git’s object database.
  5. Separate source code storage from binary artifact storage.
  6. Avoid large binary commits unless using Git LFS intentionally.

Best Practices for Production

  • Keep repositories focused on source code.
  • Use external storage (S3, artifact repositories) for large binaries.
  • Automate detection of large files in CI pipelines.
  • Add pre-commit or pre-receive hooks to block oversized files.
  • Regularly audit repository object sizes.

Conclusion

Rewriting Git history at scale is a high-impact, high-risk operation if not handled properly. However, with a structured approach, proper backups, archival strategy, and verification, it becomes a controlled and repeatable process.

By combining Git object analysis, S3 archival, and git-filter-repo, we successfully removed large files from multiple repositories without data loss and without relying on Git LFS.

This approach provides a scalable blueprint for teams facing similar migration or repository health challenges.

Related Searches

Related Solutions

From Docker Compose To Kubernetes: Simplifying Deployments With Kanvas

Continue reading “From Docker Compose To Kubernetes: Simplifying Deployments With Kanvas”

What Is DevSecOps? A Complete Guide To Secure Software Delivery

DevSecOps Overview 

DevSecOps, which connects development, security and operations, is a framework designed to incorporate security into every stage of the software development lifecycle. Organizations implement this strategy to reduce the risk of launching code that contains security vulnerabilities.  

Traditionally, security measures were often considered only at the end of the development process, almost as a secondary consideration, with a separate security team implementing these measures, followed by a separate quality assurance (QA) team verifying them. DevSecOps plays a vital role in a comprehensive multicloud security strategy. 

DevSecOps transforms security from a constraint to a collective responsibility that includes development, operations, and security teams. With the right DevSecOps services, organizations can maintain the rapid pace of DevOps while also effectively mitigating risks by automating security checks and incorporating them into CI/CD pipelines, as well as continuously monitoring applications in production.  Continue reading “What Is DevSecOps? A Complete Guide To Secure Software Delivery”

Amazon Nova Act Explained: How Action-Oriented AI Is Transforming Enterprise Automation

Artificial Intelligence is evolving fast. Previously, AI systems were primarily built to respond to questions, produce text or guide users in conversation. But today companies want more than be told how , they want it done.

Today’s enterprises need AI that can comprehend what’s desired, make determinations and take real actions across systems and tools. And this movement from conversational AI to operational AI is exactly where Amazon Nova Act comes into play.

Amazon Nova Act is Amazon’s vision of AI for action , AI that does not just speak, but acts to accomplish work. Continue reading “Amazon Nova Act Explained: How Action-Oriented AI Is Transforming Enterprise Automation”

Secure, Serverless And Private: Hosting Static Sites with AWS S3 And CloudFront OAC

Modern platforms demand architectures that are not only fast and scalable but also impossible to attack at the storage layer. A static website might seem simple, but hosting it securely on AWS—without exposing S3 to the public internet—requires careful design.

As part of my DevOps journey, I was given a straightforward but strict objective: Continue reading “Secure, Serverless And Private: Hosting Static Sites with AWS S3 And CloudFront OAC”