# Deleting files, completely, from git history

![](https://i.imgur.com/ToN09BO.png)

```shell
FILENAME=""

git filter-branch --force --index-filter \\
"git rm --cached --ignore-unmatch $FILENAME" \\
--prune-empty --tag-name-filter cat -- --all

git push origin --force --all
git push origin --force --tags
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now

```

* Specify the name of the file you want to clean with `FILENAME=""`.
* With the `git filter-branch` command, we can clean all traces of a specific file in Git history.
* The `force` parameter is used to prevent errors when the filter branch already exists.
* The `index-filter` parameter specifies the command run for each commit.
* We remove all versions of the specified file with the `git rm --cached --ignore-unmatch $FILENAME` command.
* The `prune-empty` parameter removes empty commits that do not include file changes.
* The `tag-name-filter cat -- --all` parameter performs operations on all branches and tags.
* We forcefully push the changes to the remote repository with the `git push origin --force --all` and `git push origin --force --tags` commands.
* We delete the original references with the `git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin` command.
* We clean the git history with the `git reflog expire --expire=now --all` and `git gc --prune=now` commands.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/arsiv/programming/deleting-files-completely-from-git-history.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
