# How to remove file from Git history

- **Date**: 2024-01-08
- **URL**: https://www.bhekani.com/micro/remove-file-from-git-history/

---
I have googled this enough times for me to keep it in my own notes.

From time to time I find that in my building and carelessly using `git add .` I have added a file or files into git that I shouldn't have had in there in the first place. When this happens I want to delete the file from the git history completely. Maybe there's a better way to do that but this does what I want.

Anyway, the answer to "How to remove file from Git history" that I always use is [here](https://stackoverflow.com/questions/43762338/how-to-remove-file-from-git-history). This is the specific answer I use.

```bash
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD

```
