Skip to content

Instantly share code, notes, and snippets.

@adamwalter
Last active January 25, 2019 19:01
Show Gist options
  • Save adamwalter/3cf4bf68eac0392901a61a8c39a9ee7e to your computer and use it in GitHub Desktop.
Save adamwalter/3cf4bf68eac0392901a61a8c39a9ee7e to your computer and use it in GitHub Desktop.
Remove WordPress uploads (or any large files) from a Git repo
# 1. Install BFG CLI
# https://rtyley.github.io/bfg-repo-cleaner/
brew install bfg
# 2. Download BFG
# https://rtyley.github.io/bfg-repo-cleaner/
# 3. Rename BFG's JAR file to 'bfg.jar' and move to ~/bfg.jar
# Test BFG by running empty "bfg" command
# 4. Add wp-content/uploads to your .gitignore
# 5. Remove uploads from Git
git rm -r --cached wp-content/uploads
# 6. Commit changes and push to remote
git commit -am "Removed uploads from repo"
git push
# 7. Re-clone your project as a bare repo in a different directory
git clone --mirror <your repo URL>
# 8. Run BFG
bfg --delete-folders uploads yourbarerepo.git
# 9. Move into the bare repo and purge the old files from the repo
cd yourbarerepo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# 10. Push your newly-cleaned repo to origin
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment