Skip to content
CommanderTurtlePublic

About

gahd env it, my .env was uploaded again!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Gahd D.env'it!

denvit removes one repository-relative file from every reachable commit while leaving the source repository untouched. It is deliberately small: one PowerShell implementation, one Bash implementation, and this guide.

It is useful when .env, personal.md, or another private file was committed and the rest of the project history should survive. The rewrite is powered by git-filter-repo, runs in a fresh bare mirror under ./out, prunes commits made empty by the removal, verifies the result, and stops before pushing.

Rewriting Git history changes commit IDs. If the removed file held a secret, rotate that secret too: deleting history cannot revoke a credential already copied elsewhere.

Requirements

  • Git
  • git-filter-repo
  • PowerShell 5.1+ on Windows, or Bash 4+

Install the one extra tool with:

uv tool install git-filter-repo
git filter-repo --version

Run it

Launch either script without arguments for the guided prompts:

.\denvit.ps1
./denvit.sh

Or specify everything directly:

.\denvit.ps1 -SourceMode local -Source . -Target '.env' -Mode exact -GitIgnore yes
.\denvit.ps1 -SourceMode remote -Source CommanderTurtle/example -Target 'notes/personal.md' -Mode recursive -GitIgnore yes -Yes
./denvit.sh --source-mode local --source . --path .env --mode exact --gitignore yes
./denvit.sh --source-mode remote --source CommanderTurtle/example --path notes/personal.md --mode recursive --gitignore yes --yes

-Yes/--yes accepts the displayed rewrite plan; it does not silently enable .gitignore. Pass -GitIgnore yes or --gitignore yes explicitly in unattended use.

The choices

Source

  • local accepts a working tree or bare repository path. . works.
  • remote accepts Owner/Repo, an HTTP(S) URL, an SSH URL, or an scp-style Git URL. Owner/Repo resolves to GitHub HTTPS.
  • Remote sources are cached as unsanitized bare mirrors in out/cache. A later run fetches into that cache instead of cloning the network repository again.

The scripts display the configured global user.name and user.email before remote work or creating ignore commits. Git identity is not authentication; Git Credential Manager, SSH, or the normal Git prompt still handles remote credentials.

Only committed Git history is copied. Uncommitted working-tree files and changes are intentionally not part of a history rewrite.

Removal mode

  • exact removes only the exact path entered.
  • recursive also discovers paths connected by Git rename records across all reachable refs. If place/personal.md was later renamed to personal.md, asking for personal.md removes both names. Git rename detection is similarity-based, so review the printed path list before continuing.

Both modes rewrite all reachable local branches and tags in the mirror. Commits that become empty are pruned; unrelated files, messages, authorship, dates, topology, branches, and tags are retained as far as Git's history rewrite permits. Cryptographic commit/tag signatures cannot survive a content rewrite.

.gitignore

  • gitignore=no only purges history.
  • gitignore=yes also appends a root-anchored, escaped rule for the requested path to .gitignore on every surviving branch tip.

The ignore rule is a new tip commit rather than a fabricated edit to every historical .gitignore. Existing entries are not duplicated. Tags remain attached to their rewritten historical commits and are not moved to the new branch-tip commit.

Output and pushing

Each run creates a timestamped sanitized bare mirror:

out/<repo>-sanitized-YYYYMMDD-HHMMSS.git

Before reporting success, the script checks that every selected path is absent from reachable history and runs git fsck. It then prints:

force push ready

Nothing is pushed automatically. Inspect the mirror and only then run the exact command printed by the script, normally:

git -C "<sanitized-mirror>" push --force --mirror origin

--mirror replaces the remote ref set, not merely the current branch. Coordinate with collaborators, preserve a separate backup, and have existing clones re-clone or carefully reset after the push. Hosting-provider caches, pull-request refs, forks, releases, and Git LFS objects may need provider-specific cleanup too.

The original local source and the remote cache still contain the old data. The scripts say so at the end; protect or remove those copies manually when they are no longer needed.

What it never does

  • It never edits the supplied local repository.
  • It never pushes.
  • It never deletes the source, cache, or generated mirror.
  • It never treats an absolute path as a repository path.
  • It refuses .. traversal and .git metadata targets.

Runtime data lives only in ./out, which the scripts add to this repository's local .git/info/exclude. The published project therefore remains exactly these three files.

About

gahd env it, my .env was uploaded again!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages