Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MervinPraison/e15aa6b8bed77bd2d3eea34dfd3b84e9 to your computer and use it in GitHub Desktop.
Save MervinPraison/e15aa6b8bed77bd2d3eea34dfd3b84e9 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment