November 01, 2018
Ever pushed some private stuff in a public repo and you want it to be removed? I just did..
I came across this article on github: removing-sensitive-data-from-a-repository
And solved this problem by eventually following the below - easy to follow - approach.
Just take the walk of shame and publicly remove the file you want to be removed from the repo and push the change to your remote repository. It’s essential you do this first, as otherwise, the next step will fail.
In this commit, I did exactly the same. But in my link, you won’t see the file anymore, due to the steps we will take below.
Only fools make the same mistake twice
Don’t be that fool and add the file to your gitignore, commit, and push.
This step is simple, just do
git clone your-repo somewhere else.. Just for the sake of..having a backup in case you do something wrong..
This open source repo is the key to make this task very simple. Just download the bfg repo cleaner. You will need Java on your PATH to execute it though (it’s preinstalled on Mac).
There is nothing permanent, except change - Heraclitus
Go to your command line,
cd into the cloned backup repo and run the following command to delete the file:
java -jar ~/Downloads/bfg-1.13.0.jar --delete-files THE_FILE
Follow the instructions the tool gives you on the command line, in my case this was:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
If you don’t like something, change it. If you can’t change it, change your attitude. - Maya Angelou
git status, it will look like nothing happened.. 🤔Don’t worry, that’s normal!
Just have faith and force push all-the-things!
git push origin --force --all
Surf to your repo and BAM…it will be like the file never existed… Cruel, don’t you think?
Written by Jonathan Dierckens who lives and works in Ghent, trying to build useful things.