Error: Unable to access jarfile bfg.jar - BFG

Once you've installed BFG (e.g. using brew install BFG), you can call the BFG command in terminal.
Here is the command line help for BFG:

bfg
bfg 1.13.0
Usage: bfg [options] [<repo>]

  -b, --strip-blobs-bigger-than <size>
                           strip blobs bigger than X (eg '128K', '1M', etc)
  -B, --strip-biggest-blobs NUM
                           strip the top NUM biggest blobs
  -bi, --strip-blobs-with-ids <blob-ids-file>
                           strip blobs with the specified Git object ids
  -D, --delete-files <glob>
                           delete files with the specified names (eg '*.class', '*.{txt,log}' - matches on file name, not path within repo)
  --delete-folders <glob>  delete folders with the specified names (eg '.svn', '*-tmp' - matches on folder name, not path within repo)
  --convert-to-git-lfs <value>
                           extract files with the specified names (eg '*.zip' or '*.mp4') into Git LFS
  -rt, --replace-text <expressions-file>
                           filter content of files, replacing matched text. Match expressions should be listed in the file, one expression per line - by default, each expression is treated as a literal, but 'regex:' & 'glob:' prefixes are supported, with '==>' to specify a replacement string other than the default of '***REMOVED***'.
  -fi, --filter-content-including <glob>
                           do file-content filtering on files that match the specified expression (eg '*.{txt,properties}')
  -fe, --filter-content-excluding <glob>
                           don't do file-content filtering on files that match the specified expression (eg '*.{xml,pdf}')
  -fs, --filter-content-size-threshold <size>
                           only do file-content filtering on files smaller than <size> (default is 1048576 bytes)
  -p, --protect-blobs-from <refs>
                           protect blobs that appear in the most recent versions of the specified refs (default is 'HEAD')
  --no-blob-protection     allow the BFG to modify even your *latest* commit. Not recommended: you should have already ensured your latest commit is clean.
  --private                treat this repo-rewrite as removing private data (for example: omit old commit ids from commit messages)
  --massive-non-file-objects-sized-up-to <size>
                           increase memory usage to handle over-size Commits, Tags, and Trees that are up to X in size (eg '10M')
  <repo>                   file path for Git repository to clean

2015: From the documentation, it should be:

java -jar bfg.jar <options> yourrepo

Try and use the full path of the jar if you have an error like "Unable to access jarfile bfg.jar": /home/user/path/to/bfg.jar.

If the jars are configured to be run with java, then /usr/local/bin/bfg would be the path of the symlink referencing the right bfg jar.

The alternative is described in "Remove sensitive data"

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch Rakefile' \
--prune-empty --tag-name-filter cat -- --all

Or (update Nov. 2017), as commented by JeremyDouglass,

If you download the latest (e.g. from 1.12.16, the bfg-1.12.6.jar) and you only want to use standard commands in a local staging directory only (no path, no symlink), then you can simply rename the jar:

mv bfg-1.12.16.jar bfg.jar 
java -jar bfg.jar --delete-files bad.txt repo.git

2019-2020: more recently, you would now use You should use git filter-repo (that I mentioned here).

Install it first. (python3 -m pip install --user git-filter-repo)

Then, using a path-based filter:

git filter-repo --path secrets.yml --invert-paths HEAD

HEAD means it will change only your current branch commits.
Remove HEAD and it will go over all your commits in all your branches.

Tags:

Git

Jar