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
1×
Become a member
to unlock all features

Level Up!

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

Autoplay

    Completely Remove a File from Pushed git History

    gitgit

    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:

    https://help.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository

    And the BGF itself is available here:

    https://rtyley.github.io/bfg-repo-cleaner/

    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.