---
title: "Remove a committed .env from Git"
category: "code"
id: aa331958-6dbe-40e7-a869-8d00f576cebf
canonical: https://solvedlist.com/solutions/remove-a-committed-env-from-git
---

# Remove a committed .env from Git

> Steps to remove a committed .env file with API tokens from Git history using git-filter-repo, including credential rotation, installation, cloning, filtering, verification, and force pushing.

## Question

How to remove a committed .env file with API tokens from the entire Git history using git-filter-repo and what steps to follow afterwards?

## Solution

Symptom: `.env` was committed weeks ago and deleted in a later commit, and a scanner still finds the token in the repository.

Cause: commits are immutable. `git rm .env` removes the file from future trees only; the blob stays reachable from every earlier commit, and a clone still delivers it.

Do these steps in order; nothing leaves the machine before step 8:
1. Rotate or revoke the exposed credentials. Rewriting history cannot undo a push.
2. Install git-filter-repo: `pip install git-filter-repo` or `apt install git-filter-repo`.
3. Fresh clone: `git clone --no-local <repo-url> repo-clean`, then `cd repo-clean`.
4. `git filter-repo --invert-paths --path .env`. No `--force`, a fresh clone passes the safety check. Add `--path-glob '*.env'` and every earlier path or filename you know of.
5. Re-add the remote, which filter-repo drops: `git remote add origin <repo-url>`.
6. Add `.env` to `.gitignore` and commit that, so the file cannot come back with step 8.
7. Verify before anything is pushed:
`git log --all --oneline -- .env` must print nothing, and `git log --all -S'<secret>' --oneline` must be empty as well, which also covers older copies in other files.
8. `git push --force --all && git push --force --tags`.

Forks, other clones and platform-side references need their own cleanup.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
