The BFG Repo-Cleaner is a tool that's built and maintained by the open source community. It provides a faster, simpler alternative to git filter-branch for removing unwanted data.
--- title: Purging a file from your Git repository's history subtitle: "The BFG Repo-Cleaner is a tool that's built and maintained by the open source community. It provides a faster, simpler alternative to git filter-branch for removing unwanted data." author: GitHub Docs date: December 31, 2020 source: https://docs.github.com/github/authenticating-to-github/removing-sensitive-data-from-a-repository notoc: false --- If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the `git filter-branch` command or the BFG Repo-Cleaner open source tool. ## Using the BFG The [BFG Repo-Cleaner](http://rtyley.github.io/bfg-repo-cleaner/) is a tool that's built and maintained by the open source community. It provides a faster, simpler alternative to `git filter-branch` for removing unwanted data. For example, to remove your file with sensitive data and leave your latest commit untouched, run: ```bash $ bfg --delete-files YOUR-FILE-WITH-SENSITIVE-DATA ``` To replace all text listed in `passwords.txt` wherever it can be found in your repository's history, run: ```bash $ bfg --replace-text passwords.txt ``` After the sensitive data is removed, you must force push your changes to GitHub. ```bash $ git push --force ``` See the [BFG Repo-Cleaner's](http://rtyley.github.io/bfg-repo-cleaner/) documentation for full usage and download instructions. ## Installing BFG Repo-Cleaner - [macOS](#installing-bfg-repo-cleaner-on-macos) - [Windows](#installing-bfg-repo-cleaner-on-windows) ### Installing BFG Repo-Cleaner on macOS To install BFG Repo-Cleaner from the command using [Homebrew](https://brew.sh/): ```bash brew install bfg ``` ### Installing BFG Repo-Cleaner on Windows After [downloading](https://rtyley.github.io/bfg-repo-cleaner/) the BFG Repo-Cleaner jar file, move it to the `C:\bin\lib\bfg` folder (full path should be `C:\bin\lib\bfg\bfg.jar`). Create a new file called `bfg.cmd` and save it to a folder called `C:\bin`. Copy the following contents into the `bfg.cmd` file: ```cmd @echo off REM Usage: bfg [options] [<repo>] java -jar "%~dp0lib\bfg\bfg.jar" %* ``` Assuming `C:\bin` has already been added to your environment's `%Path%` variable, you can now run BFG Repo-cleaner from anywhere using command `bfg`.--- title: Purging a file from your Git repository's history subtitle: ## Using git filter-branch See [GitHub Docs](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/removing-sensitive-data-from-a-repository#using-filter-branch) for git filter branch example.