Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Remove sensitive folders (e.g. a private image gallery) from a remote repository with BFG.

Tags: git

BFG helped remove sensitive images from a remote repository. The bad folders were gallery and –gallery. It could also work with App_Data and Media (e.g. in Orchard).

First, make a clean commit.

This is vital!

  1. Create a .gitignore file. Add the sensitive folders to it.
  2. Make sure the most recent commit does NOT have any of the bad folders!!
git rm –r –cached gallery

git rm –r –cached ‘–gallery’

git commit –m "Remove sensitive folders.";

git push

Then, clean the remote and its history.

  1. Install the JAVA runtime environment (BFG requires it.)
  2. Download BFG: http://rtyley.github.io/bfg-repo-cleaner/

    • Then rename the download file to bfg.jar
    • Then copy-paste it to the desktop

  3. Open PowerShell at the desktop.
  4. Then run these commands:
git clone --mirror https://github.com/bigfont/my-repository.git

java -jar .\bfg.jar --delete-folders '{-gallery,gallery}' .\my-repository.git

cd .\my-repository.git

git reflog expire --expire=now –all

git gc --prune=now –aggressive

git push