Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Completely Remove a File from Pushed git History


    If we want to completely remove a file from github - including all history - there is a tool that we can use called the BFG.

    The github help article is here:

    And the BGF itself is available here:

    We'll start by downloading the BFG jar file, and then cloning a mirror of our repo with:

    git clone --mirror [repo-url]

    Then we can delete our .env file with:

    java -jar ~/Downloads/bfg-1.13.0.jar --delete-files .env my-repo.git

    which will delete the .env file. Then we can use the following command to prune the entire history and garbage collect the remains:

    git reflog expire --expire=now --all && git gc --prune=now --aggressive

    And finally, use git push to push that change to github, and remove the .env file from all of the history on github as well.