git-rewrite-history
MANDATORY: Use instead of `git filter-branch` - safer git-filter-repo with recovery
What this skill does
# Git Rewrite History Skill
**Purpose**: Safely rewrite git history using `git-filter-repo`, the modern replacement for
`git filter-branch`.
## Why git-filter-repo over git-filter-branch
**Always use `git-filter-repo` instead of `git filter-branch`**. Git itself warns against filter-branch:
> git-filter-branch has a glut of gotchas generating mangled history rewrites.
> Use git-filter-repo instead.
| Feature | git-filter-repo | git-filter-branch |
|---------|-----------------|-------------------|
| Speed | 10-50x faster | Slow |
| Safety | Handles edge cases | Many gotchas |
| Maintenance | Actively maintained | Deprecated |
| Syntax | Simple, intuitive | Complex, error-prone |
## Installation
```bash
pip install git-filter-repo
# or
pip install --break-system-packages git-filter-repo
```
## Safety Pattern: Backup-Verify-Cleanup
**ALWAYS follow this pattern:**
1. **Work on a fresh clone** (filter-repo requires this by default)
2. Create backup of original remote URL
3. Execute the filter operation **with `--partial`** (preserves reflog for recovery)
4. **Verify immediately** - check history is correct
5. Force push only after verification and explicit user approval
### MANDATORY: Always Use --partial Flag
**Always include the `--partial` flag with git-filter-repo**. Without it:
- Reflog is expired (old commits unrecoverable)
- Automatic `git gc` runs (objects permanently deleted)
- No recovery possible after force-push
With `--partial`:
- Old commits preserved in reflog
- Recovery via `git reset --hard HEAD@{n}` possible
- New history is active, old history available as fallback
## Common Operations
### Remove a File from All History
```bash
# Fresh clone required
git clone --mirror <url> repo-filter
cd repo-filter
# Remove file (--partial preserves reflog for recovery)
git filter-repo --partial --path secrets.txt --invert-paths
# Verify
git log --all --oneline -- secrets.txt # Should return nothing
# If wrong, recover: git reflog && git reset --hard HEAD@{n}
# Push only after verification (requires explicit user approval)
git push origin --force --all
```
### Remove a Directory from All History
```bash
git filter-repo --partial --path vendor/ --invert-paths
```
### Remove a Submodule from History
```bash
# This removes the gitlink entry for a submodule
git filter-repo --partial --path submodule-name --invert-paths
```
### Rename/Move Files in History
```bash
# Rename a file across all history
git filter-repo --partial --path-rename old-name.txt:new-name.txt
# Move directory
git filter-repo --partial --path-rename old-dir/:new-dir/
```
### Remove Large Files
```bash
# Remove files larger than 10MB
git filter-repo --partial --strip-blobs-bigger-than 10M
```
### Keep Only Specific Paths
```bash
# Keep only src/ directory (remove everything else)
git filter-repo --partial --path src/
```
### Filter by Content (Remove Secrets)
```bash
# Replace text patterns
git filter-repo --partial --replace-text expressions.txt
# Where expressions.txt contains:
# PASSWORD=secret123==>PASSWORD=REDACTED
# regex:api_key=\w+==>api_key=REDACTED
```
## Working on Existing Clone
By default, git-filter-repo requires a fresh clone. To work on an existing repo:
```bash
# --partial preserves reflog, --force allows non-fresh clone
git filter-repo --partial --force --path file-to-remove --invert-paths
```
## After Rewriting History
1. **All collaborators must re-clone** or reset their branches
2. **Force push required**: `git push --force-with-lease origin <branch>`
3. **Update any CI/CD** that caches the old commits
4. **GitHub/GitLab**: May need to run garbage collection on server
## Verification Checklist
- [ ] Target files/paths no longer in history: `git log --all -- <path>`
- [ ] Commit count is expected
- [ ] No unexpected files removed: `git diff --stat <old-commit>..<new-head>`
- [ ] Build still works
- [ ] Tests pass
## Recovery
If something goes wrong (before force-push):
```bash
# With --partial, old history is in reflog
git reflog # Find old commit (e.g., HEAD@{2})
git reset --hard HEAD@{2} # Restore to pre-filter state
# If you have original remote (after force-push)
git fetch origin
git reset --hard origin/<branch>
# If you kept a backup branch
git reset --hard backup-before-filter
```
**CRITICAL**: Recovery from reflog only works if:
1. You used `--partial` flag
2. You haven't force-pushed yet (or haven't run `git gc`)
## When to Use This Skill
- Removing accidentally committed secrets
- Removing large binary files to reduce repo size
- Removing submodules from history
- Restructuring repository paths
- Splitting a repository
## References
- [git-filter-repo documentation](https://github.com/newren/git-filter-repo)
- [GitHub: Removing sensitive data](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.