{"data":{"slug":"discovered-08834c58e88ab66ef988d627b28b2f36acc95af554c0f379","title":"Git Hygiene","summary":"Prevent, detect, and remediate files that should never be committed \u2014 secrets (.env, API tokens, hardcoded credentials) and dev artifacts (build output, scratch databases, editor\/OS files). Use when a repo has committed secrets or junk, when setting up a new repo's ignore rules, or when reviewing what a repo actually tracks.","url":"https:\/\/skillshunter.net\/skills\/discovered-08834c58e88ab66ef988d627b28b2f36acc95af554c0f379","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-08834c58e88ab66ef988d627b28b2f36acc95af554c0f379","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-08834c58e88ab66ef988d627b28b2f36acc95af554c0f379.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-08834c58e88ab66ef988d627b28b2f36acc95af554c0f379\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before committing any changes, rotate secrets to ensure they are no longer valid. This is the first and most critical step in protecting against exposure from history.","instructions":"---\nname: keeping-git-repos-clean\ndescription: Prevents, detects, and remediates files that should never be committed \u2014 secrets (.env, API tokens, hardcoded credentials) and dev artifacts (build output, scratch databases, editor\/OS files). Covers .gitignore (and why it does not untrack), git rm --cached, auditing tracked files, history scrubbing, and credential rotation. Use when a repo has committed secrets or junk, when setting up a new repo's ignore rules, or when reviewing what a repo actually tracks.\n---\n\n# Keeping Git Repos Clean\n\nTwo classes of files keep ending up in repos: **secrets** and **dev artifacts**.\nBoth are cheap to prevent and expensive to clean up after the fact, because git\nhistory is forever and public repos publish everything.\n\n## The one rule everyone forgets\n\n**`.gitignore` does NOT untrack files that are already committed.** Adding a path\nto `.gitignore` only prevents *future untracked* files from being staged. A file\ngit is already tracking keeps getting committed regardless. This bites repeatedly:\na `.env` is listed in `.gitignore` but was committed before the rule existed, so\nit keeps shipping.\n\nTo actually stop tracking a file while keeping your local copy:\n\n```bash\ngit rm --cached path\/to\/file        # untrack, leave working-tree copy in place\ngit rm -r --cached some\/dir\/        # for a directory\necho \"path\/to\/file\" >> .gitignore   # then ignore it so it doesn't come back\ngit commit -m \"Stop tracking <file>; add to .gitignore\"\n```\n\n`--cached` is the important flag \u2014 plain `git rm` deletes the working copy too.\n\n## Audit what a repo actually tracks\n\nDon't trust `.gitignore` to tell you what's clean \u2014 read the index directly:\n\n```bash\ngit ls-files | grep -iE '\\.(env|pem|key|p12|profraw|log|bak|db|sqlite3?)$'\ngit ls-files | grep -iE '(^|\/)(\\.DS_Store|~\\$|todo\\.db|node_modules\/|__pycache__\/)'\ngit ls-files '*.db' '*.sqlite*'                 # scratch databases\ngit ls-files | xargs -I{} du -h {} | sort -rh | head   # surprisingly large tracked files\n```\n\nUsual suspects seen across real repos:\n\n- **Secrets:** `.env` with a live token, hardcoded `AWS_*`\/DB creds in a settings\n  module, `SECRET_KEY = \"CHANGEME\"`\/`\"foobar\"` placeholders shipped to prod.\n- **Build artifacts:** LaTeX `.aux\/.toc\/.log\/.synctex.gz\/.pdf`, LLVM `*.profraw`,\n  compiled binaries, `htmlcov\/`, `dist\/`, `*.egg-info\/`.\n- **Scratch \/ personal artifacts:** `todo.db` and other tool-local SQLite scratch\n  DBs, editor backups (`*.backup`, `*.bak`, `~$*.docx` Word lock files), stray\n  `*.log`.\n- **OS noise:** `.DS_Store`, `Thumbs.db`.\n\n## Secrets need more than `git rm`\n\nRemoving a secret from `HEAD` does **not** remove it from history \u2014 `git log -p`\nand the commit that introduced it still expose it. Three things must happen, in\norder, and the first is the only one that actually protects you:\n\n1. **Rotate the credential.** Treat any secret that ever touched a remote as\n   compromised. Issue a new token\/key\/password and revoke the old one. Do this\n   first \u2014 the leaked value is public the moment it was pushed.\n2. **Untrack going forward** (`git rm --cached` + `.gitignore` + `.env.example`\n   documenting which vars are needed, with placeholder values only).\n3. **Scrub history** if required (`git filter-repo --invert-paths --path .env`,\n   or BFG) and force-push. This rewrites SHAs and disrupts collaborators, so it's\n   usually a deliberate maintainer step done after rotation \u2014 not an automated PR.\n\nA PR that does (2) and (3) but skips (1) gives false comfort: the value is still\nvalid and still in history clones\/forks. Always call out rotation as the required\nhuman follow-up.\n\n## \"Committed\" means \"published\"\n\nFor public repos \u2014 and especially static sites deployed with `path: '.'`\n(GitHub Pages uploads the entire repo) \u2014 every tracked file is fetchable at a\npublic URL. A scratch `todo.db` at the repo root of a brochure site is served at\n`\/todo.db`. Before committing to any public repo, assume anyone can download it.\n\n## Prevent it: global ignore + a secret scanner\n\nPer-developer noise (editor files, OS files, tool scratch DBs like `todo.db`)\nshould be ignored **globally**, not in every project's `.gitignore` \u2014 that way it\nnever lands anywhere:\n\n```bash\ngit config --global core.excludesFile ~\/.gitignore_global\nprintf '%s\\n' '.DS_Store' '*.swp' 'todo.db' '*.profraw' >> ~\/.gitignore_global\n```\n\nBlock secrets at commit time with a pre-commit hook so they never reach history:\n\n```yaml\n# .pre-commit-config.yaml\nrepos:\n  - repo: https:\/\/github.com\/gitleaks\/gitleaks\n    rev: v8.18.0\n    hooks: [{id: gitleaks}]\n  - repo: https:\/\/github.com\/Yelp\/detect-secrets\n    rev: v1.5.0\n    hooks: [{id: detect-secrets, args: [\"--baseline\", \".secrets.baseline\"]}]\n```\n\nA starter project `.gitignore` (commit this):\n\n```gitignore\n# Secrets \/ local config\n.env\n.env.*\n!.env.example\n*.pem\n*.key\n\n# Python build\/test artifacts\n__pycache__\/\n*.py[cod]\nbuild\/\ndist\/\n*.egg-info\/\n.coverage\nhtmlcov\/\n.pytest_cache\/\n\n# Scratch \/ OS \/ editor\n*.db\n*.sqlite\n*.sqlite3\n*.profraw\n*.log\n*.bak\n*.backup\n.DS_Store\n~$*\n```\n\n## Verification can dirty the tree\n\nCompilers, test runners, and asset pipelines often write into the checkout even\nwhen the command is only meant to verify a change. They may create unignored\ncache files or regenerate a tracked distributable such as a PDF or compiled CSS.\nA green command does not mean the working tree still contains only your change.\n\nBracket verification with status checks and stage only reviewed paths:\n\n```bash\ngit status --short\nmake test                         # or the project's real build command\ngit status --short\ngit diff -- path\/you\/changed\ngit add path\/you\/changed          # never sweep in generated files with git add -A\ngit diff --cached --check\ngit diff --cached --stat\n```\n\nIf a tool necessarily produces noisy output, run it in a disposable copy of the\ncheckout. This preserves a real build while keeping generated files away from\nthe patch:\n\n```bash\nscratch_dir=$(mktemp -d)\nrsync -a --exclude .git .\/ \"$scratch_dir\/\"\n(cd \"$scratch_dir\" && make build)\n```\n\nWhen verification modifies a tracked generated output that is intentionally out\nof scope, restore **that exact path only after reviewing its diff**:\n\n```bash\ngit diff -- docs\/manual.pdf\ngit restore -- docs\/manual.pdf\n```\n\nDo not use a broad restore\/reset to clean up: the checkout may already contain\nsomeone else's work. Also do not rely on `git stash` as cleanup for untracked\nartifacts; ordinary stashes omit them, and even `--include-untracked` can collide\nwith files regenerated before `stash pop`. Prevent or remove known generated\npaths explicitly instead.\n\n## Checklist\n\n```\nAudit:\n- [ ] `git ls-files` reviewed for secrets, build output, scratch DBs, OS files\n- [ ] No live credentials in tracked source or .env\n- [ ] No surprisingly large\/binary tracked files\n\nRemediate (if dirty):\n- [ ] Secret rotated\/revoked FIRST (history is public the moment it was pushed)\n- [ ] `git rm --cached` + .gitignore entry for each offending file\n- [ ] .env.example documents required vars with placeholder values only\n- [ ] History scrub flagged as a maintainer follow-up if the secret is in history\n\nPrevent:\n- [ ] Project .gitignore covers secrets, build artifacts, OS\/editor noise\n- [ ] Global core.excludesFile catches per-developer scratch files\n- [ ] gitleaks \/ detect-secrets pre-commit hook installed\n- [ ] Verification bracketed by `git status --short`; only reviewed paths staged\n```\n\nFor scanning source code for vulnerabilities and hardcoded-secret *patterns*\nrather than what git tracks, use the `\/security-review` skill already available\nin this session.\n\n## Note for this repository (ffmpeg-skill)\n\n`.gitignore` already covers `__pycache__\/`, and `package.json`'s `\"files\"` list\nis the actual publish gate \u2014 but this session hit exactly the \"verification can\ndirty the tree\" case: running `python3 scripts\/proxy.py` and the test suites\nlocally created `__pycache__\/*.pyc` files that then showed up in an `npm\npublish --dry-run` listing before they were deleted. The `git status --short`\nbracket-and-check habit above (or, cheaper here, just re-running the dry-run\nafter deleting stray `__pycache__\/` directories) is the concrete fix. There\nare no secrets or `.env`-shaped files in this repo (no cloud\/API keys by\ndesign), so the credential-rotation half of this skill does not currently\napply \u2014 the dev-artifact half is the one worth watching.\n\nSource: [wdm0006\/python-skills](https:\/\/github.com\/wdm0006\/python-skills) (MIT).\n","use_cases":["Removing secrets from a repository's history","Setting up a new repository with proper .gitignore rules","Auditing a repository to identify untracked or tracked files that should not be committed"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/kajisho5\/ffmpeg-skill\/blob\/daae28ea4fe27223932392be07206798423c0f8b\/.claude\/skills\/git-hygiene\/SKILL.md","source_commit":"daae28ea4fe27223932392be07206798423c0f8b","license":null,"version":null,"listing_approved_at":"2026-11-28","created_at":"2026-11-28T08:11:16.000000Z","updated_at":"2026-11-28T18:38:03.000000Z","seo_title":"Git Hygiene: Preventing Secrets and Artifacts in Git Repos","seo_description":"Learn how to prevent, detect, and remediate files that should never be committed \u2014 secrets and dev artifacts \u2014 in your Git repositories.","seo_keywords":["git hygiene","git secrets","git dev artifacts","git repo cleanup","git ignore rules","git history scrubbing"]}}