Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Created September 13, 2012 00:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save wrburgess/3711050 to your computer and use it in GitHub Desktop.
Save wrburgess/3711050 to your computer and use it in GitHub Desktop.
Permanently remove file from Git history

Reference

Remove sensitive files from Git/Github

In Terminal

git filter-branch --index-filter 'git rm --cached --ignore-unmatch [file path/name]' --prune-empty --tag-name-filter cat -- --all

Example:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch config/database.yml' --prune-empty --tag-name-filter cat -- --all

Add file to .gitignore

echo "[filename]" >> .gitignore
git add .gitignore
git commit -m "Add [filename] to .gitignore"

Example:

echo "Rakefile" >> .gitignore
git add .gitignore
git commit -m "Add Rakefile to .gitignore"

Push the changes to origin repo:

git push origin master --force
@eminx
Copy link

eminx commented Mar 29, 2020

Oh man the settings file is entirely gone from all branches now.

One should copy the file before permanently deleting it.

But thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment