Skip to main content

Purge Git History

Use the information in this document to delete content from git repositories and purge them from commit histories. This is useful in the following situations:

  1. Removing large files that accidentally got committed.
  2. Removing sensitive content, such as private/secret keys, that got committed.

Prerequisites

BFG Installation

  1. Download the latest BFG jar from the above link.
  2. Save it to a common folder such as C:\bfg\
  3. optionally create a script and add it to your path variable
    1. Create an empty text file named bfg.cmd
    2. Add the line: java -jar C:\bfg\bfg-1.14.0.jar %*
    3. Save and close the cmd file.
    4. Add C:\bfg to your system PATH variable.

Steps to Purge Strings

  1. Ensure you meet the prerequisites above.
  2. Navigate to the offending repository.
  3. Create a text file where each line consists of the string(s) you wish to purge.
  4. From command line, run the command: bfg --replace-text to_remove.txt .
  5. Run the command git reflog expire --expire=now --all && git gc --prune=now --aggressive
  6. Then finally push the changes with git push