Skip to content

Instantly share code, notes, and snippets.

@wesort
Created July 30, 2024 16:42
Show Gist options
  • Save wesort/79e3884ad329404c4751947f9c7fd32a to your computer and use it in GitHub Desktop.
Save wesort/79e3884ad329404c4751947f9c7fd32a to your computer and use it in GitHub Desktop.
Using git-filter-repo to rewrite history

Remove large or sensitive files

Warning: This process rewrites history. Teams beware!

I've found this useful to remove images from being stored within a Statamic website's repo and instead being backed-up to Digitalocean spaces. GitHub recommends this and I've followed this process a few times. Your mileage may vary.


1. Check current size of repo (on dev server or locally):

  • Nav to repo
  • Check repo size: git count-objects -v
  • Take a screenshot

2. Install newren/git-filter-repo

  • sudo apt install git-filter-repo

3. Add paths to remove to .gitignore

4. Run command to remove directories or files from Git's history:

  • Nav to repo
  • To remove this directory: "/public/main/", run git-filter-repo --invert-paths --path public/main/ --force

5. Check new size of repo

  • git count-objects -v
  • This should be smaller than before.

6. Commit and force push

  • git add .
  • git commit -m "remove images assets from repo"
  • git push --force --all

7. Update other repos / enviroments

  • Login to other servers or tell colleagues to run git pull --rebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment