How to use BFG Repo-Cleaner In GIT
The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:
- Removing Crazy Big Files
- Removing Passwords, Credentials & other Private data
Download BFG Repo-Cleaner:
Download the latest version from the official site.
Command to Remove the File:
java -jar bfg.jar --delete-files gfg.jpg
Follow-Up Commands:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push origin --force --all
Explanation of the Commands:
- java -jar bfg.jar –delete-files gfg.jpg: Runs BFG to remove all occurrences of gfg.jpg from history.
- git reflog expire –expire=now –all: Cleans up the reflog.
- git gc –prune=now –aggressive: Garbage collects to remove all traces of the file.
- git push origin –force –all: Force pushes the rewritten history to the remote repository.
Successful Removal Output:
If the file was successfully removed, you’ll see output similar to:
BFG Repo-Cleaner v1.13.0
Cleaning--------Found 3 commits
Cleaning commits: 100% (3/3)
Cleaning commits completed in 100 ms.
BFG Repo-Cleaner done! Removed files and cleaned commits.
Preventing Future Issues
Update your .gitignore file to prevent accidentally committing similar files again.
How to Remove a Large File from Commit History in Git?
Simply removing a large file through a commit won’t truly eliminate it. Git stores all versions of files in its history, even deleted ones, to allow for easy recovery. This can lead to wasted disk space.
We will discuss the various approaches for removing a large file from the commit history in Git:
Table of Content
- Using git filter-branch
- Using git filter-repo
- Using BFG Repo-Cleaner
Contact Us