> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/arsiv/programming/deleting-files-completely-from-git-history.md).

# Deleting files, completely, from git history

git, programming, typescript, git history, clean git history, delete files

![](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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
