How to Remove Large Files from Git History Without Breaking Your Branches

Jimoh Sherifdeen / September 14, 2025

3 min read

Introduction

We’ve all been there. You accidentally commit a huge file — maybe a .zip, a node_modules, or even a sensitive file — and push it to GitHub. Suddenly, your repository is bloated, your pushes are slow, or GitHub even rejects it because the file exceeds size limits.

The good news: you can fix this with git filter-repo.

But there’s a catch. After cleaning the repo, you might face this dreaded GitHub message when opening a Pull Request:

“There isn’t anything to compare. develop and feat-branch are entirely different commit histories.”

Let’s walk through how to properly remove large files and keep your branches working.

Step 1: Identify and Remove the File

Run git filter-repo to remove the unwanted file from your Git history:

git filter-repo --path path/to/large-file.zip --invert-paths

--path: specifies the file you want to target. --invert-paths: means “remove this path from history.”

At this point, your branch’s entire history is rewritten with new commit SHAs (clean of that file), if you want to know, try open a PR with the base branch.

Step 2: Why GitHub Shows “Different Commit Histories”

Since git filter-repo rewrites history, your cleaned branch no longer shares a common ancestor with branches that weren’t cleaned (e.g., /master).

That’s why GitHub can’t compare them. To Git, they look like two unrelated repos.

Step 3: Reconnect Your Branch

To fix this, rebase the cleaned branch onto the base branch:

# Switch to your cleaned branch git checkout feat-branch-clean # Rebase it onto develop (rewriting from the root) git rebase --onto origin/develop --root # Push it back forcefully (since history changed) git push -f origin feat-branch-clean

Now, your branch is aligned with develop again, and GitHub will let you open PRs.

Step 4: Don’t Forget Collaborators

If others are working on the repo, they’ll need to re-clone or reset their local branches because the history has changed.

A safe step:

git fetch origin git reset --hard origin/develop

Key Lessons

  • Don’t panic if you commit a large file. Git has tools to fix it.

  • Always clean all branches that matter — not just the feature one.

  • If you see the “different commit histories” error, rebase with --onto origin/master --root.

  • Be careful with git push -f. Coordinate with your team.

✅ With this workflow, you can remove unwanted files, keep your repo clean, and still maintain a smooth GitHub workflow.