/awesome-agent-skills:awesome-git-history-resetfrom awesome-agent-skills
Collapses a Git repository's entire history into a single commit and force-pushes, with safety gates including access checks, mirror backup, and secret scanning.
Ships in awesome-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Collapse a repository's entire history into one fresh Initial commit and force-push it, so the published commit log starts clean. The file tree is preserved byte-for-byte; only the history leading to it is discarded.
Why the ceremony: this is an irreversible, outward-facing rewrite of a shared remote. Once you force-push, every old commit on the default branch is gone from the tip, open pull requests break, and anyone who cloned or forked keeps the old history anyway. The steps below are not bureaucracy — each one closes a specific way this goes wrong: pushing without write access, discovering too late that the branch was protected, losing content in the squash, or force-pushing over a teammate's commit you never saw.
NOTHING IRREVERSIBLE UNTIL FOUR THINGS HOLD: write access is confirmed, a mirror backup exists and is verified, the history is scanned for secrets, and the user has explicitly confirmed the wipe. If any one is missing, stop at that gate.
Four invariants hold throughout:
main. Detect it from the remote. Rewriting the wrong branch, or one that isn't the default, silently leaves the real history in place./awesome-git-history-reset <repository-url> [branch] [--message "Initial commit"]
<repository-url> — required. HTTPS or SSH (https://github.com/owner/repo.git or [email protected]:owner/repo.git).[branch] — optional. Defaults to the remote's detected default branch. Only pass this to target a non-default branch.--message — optional. The single commit's message. If omitted, Phase 0 asks for it at preflight (default Initial commit).If the user invokes the skill without a URL, ask for one before doing anything else.
git --version — required. Everything destructive is plain git; the host tooling below only powers the preflight gates.gitleaks version — optional: scans history for secrets before the rewrite. Without it, note that history was not scanned.Confirm each is on PATH (exit 0) before relying on it. Never assume a host CLI or gitleaks is installed.
Which host CLI. Detect the host from the remote URL, then use its tool. The gates in Phase 0 give the command for each:
| Host | CLI | Check it's present | Generic escape hatch |
|---|---|---|---|
| GitHub | gh | gh --version | gh api <endpoint> |
| GitLab (SaaS or self-managed) | glab | glab --version | glab api <endpoint> (--hostname for self-managed) |
| Bitbucket, Gitea/Forgejo, Azure DevOps, plain SSH remote | none assumed | — | the host's REST API over curl with a token, if the user supplies one |
Where the curl fallback is used, read the token from an environment variable and pass it from there. Never print it in a command, a log line or the report, and if the user pasted one into the chat, say so and advise revoking it and issuing a new one.
For a host with no CLI and no token, treat every gate below that needs one as unavailable, not as passed: list which checks you could not run, and get the user's explicit acceptance before Phase 1. An unrunnable gate is a blind spot to disclose, never a gate to skip silently.
Do every check that your available tools allow. Each failure is a hard stop, not a warning to push past.
Parse the URL into <owner>/<repo>; keep the URL verbatim for git, derive owner/repo for gh.
Read access + existence — the cheapest real check:
git ls-remote <repository-url>
Non-zero exit or auth prompt → stop. The URL is wrong, the repo is private and you're unauthenticated, or the network is down.
Hard rule — the remote's owner must match your git identity. Rewriting history on a repo you don't own is almost always a mistake (wrong clone URL, a colleague's repo, an upstream you meant to fork). Compare the repo owner against the identity that will push:
git config user.name
git config user.email
gh api user -q .login # GitHub — the account that will actually push
glab api user # GitLab — read `username` from the JSON
glab api has no field-selection flag: it prints JSON, so read the field yourself rather than piping through a jq you haven't confirmed is installed. The repo owner is <owner> (from the URL, or gh repo view <owner>/<repo> --json owner / the namespace.full_path field of glab api projects/<url-encoded-path>). With a host CLI present, the authoritative comparison is <owner> vs the authenticated login, case-insensitive; for an org- or group-owned repo the logins won't match by name — fall back to the write-permission check in step 6 as proof of ownership. With no host CLI, match <owner> against git config user.name or the local-part of git config user.email. Mismatch → stop and report it: name the repo owner and your local git identity side by side, and do not proceed until the user explicitly confirms they intend to rewrite a repo owned by a different account. Hard stop, not a warning to skip.
Detect the default branch (unless a branch was passed):
git ls-remote --symref <repository-url> HEAD
Read the ref: line — that ref (e.g. refs/heads/main) is the default branch. Use its short name as <branch>. Do not hardcode main.
Hard rule — more than one branch means stop and ask. Extra branches keep the old history reachable (so the "clean history" is incomplete), and usually mean the repo holds work you're about to strand.
git ls-remote --heads <repository-url>
More than one branch → stop, list every branch, and offer the user the choice explicitly: continue anyway (only <branch> is rewritten; the other branches keep their full history) or abort. Do not decide this yourself. Exactly one branch → continue.
Write / admin permission (needs a host CLI):
gh repo view <owner>/<repo> --json viewerPermission,isFork,parent,forkCount
glab api projects/<url-encoded-path> # read permissions, forked_from_project, forks_count
GitHub: viewerPermission must be WRITE, MAINTAIN, or ADMIN; READ / null → stop, you cannot push. GitLab: the effective access_level under permissions.project_access (or permissions.group_access) must be ≥ 40 (Maintainer) — 30 (Developer) cannot force-push a protected branch and usually cannot push to the default one. Note whether the repo is a fork (isFork / forked_from_project) — rewriting a fork's history is fine but doesn't touch the upstream; make sure that's what the user wants.
Token scopes. gh auth status prints them. repo (GitHub) / write_repository (GitLab) covers the force-push itself. workflow (GitHub) is also required when the tree holds .github/workflows/**: the single commit re-adds every workflow file, and without the scope the push is rejected with refusing to allow an OAuth App to create or update workflow. Almost every repo with CI hits this, so check it now rather than at the push. An org that enforces SSO also needs the token authorized for it; a 403 carrying an SSO header means it is not.
URL-encode the GitLab project path: group/sub/repo → group%2Fsub%2Frepo. Inside a checkout of that project, glab api projects/:fullpath substitutes it for you.
Branch protection (needs a host CLI) — force-push to a protected default branch will be rejected at push time, after the backup and squash are already done:
gh api repos/<owner>/<repo>/branches/<branch>/protection
glab api projects/<url-encoded-path>/protected_branches/<branch>
A 200 with force-push disallowed, or required reviews / linear-history / status checks → stop and tell the user to lift protection or grant a bypass first (GitHub: Settings → Branches; GitLab: Settings → Repository → Protected branches, where allow_force_push is the field that matters). A 404 means the branch is unprotected — good.
Push protection (secret scanning) is a separate rule that also rejects at push time, and the single commit presents the whole tree to it as new content:
gh api repos/<owner>/<repo> --jq .security_and_analysis
secret_scanning_push_protection reading enabled means a secret in the current tree will get the push rejected. The field is absent without admin rights, and an organization-level policy may not show in it: absent means unknown, never off. If the Phase 2 scan finds a secret in the tree at the tip, say upfront, before Phase 3, that the push will be rejected.
Open pull / merge requests (needs a host CLI) — they reference old commits and break on a wholesale rewrite. Both commands page at 30 rows by default, so get the full count first and treat a list that stops at its limit as truncated:
gh api "search/issues?q=repo:<owner>/<repo>+is:pr+is:open&per_page=1" --jq .total_count
gh pr list --repo <owner>/<repo> --state open --limit 200
glab mr list --repo <owner>/<repo> --per-page 100 # open MRs; add --page N until a page comes back empty
Any open PR/MR → surface the list, with its count against the total. Rows equal to the limit, or fewer rows than the total, mean the list is truncated: raise the limit or page on, and until then mark the output as truncated in the preflight rather than reporting it as the full set. The user should close or merge them first; proceeding will orphan their base commits.
Forks (from step 6 — forkCount on GitHub, forks_count on GitLab) — a rewrite cannot reach a fork; every forker keeps a full copy of the old history. If the count is above zero, say so plainly: this is not a way to make the old history unrecoverable.
Commit message. Ask the user what to name the single commit the whole history collapses into — unless --message was already passed on invocation. Offer Initial commit as the default so they can accept it in one word. Record the answer as <message>; Phase 3 commits with it verbatim, and the confirmation gate below quotes it back.
Confirmation gate. State exactly what will happen, then get an explicit yes:
This will permanently erase all history on
<branch>of<owner>/<repo>and replace it with a single commit (<message>), then force-push. Old commits will be unrecoverable from the remote tip (a verified backup is kept locally). Open PRs will break; existing forks keep the old history. Proceed?
No explicit confirmation → stop here. Everything up to this point was read-only.
A mirror clone is the rollback path. Make it before touching anything. A path of that name already there is an earlier backup of the same tip. It is kept and never written into, cleared or reused: take the next free name, say which one this run made, and tell the user the older backup is still on disk. A backup is the one artifact that is never put in a temporary folder, because the folder that gets cleaned is the one holding the only copy.
git clone --mirror <repository-url> <repo>-backup-<shortsha>.git
Then verify it — an unverified backup is not a backup:
cd <repo>-backup-<shortsha>.git
git rev-list --all --count # must be > 0
git log --oneline -1 <branch> # record this as OLD_SHA
git fsck --full # no missing/broken objects
Git LFS: git lfs ls-files non-empty → a mirror clone holds pointers, not blobs. Run git lfs fetch --all inside the backup, or the backup cannot restore the files.
Record OLD_SHA (the pre-rewrite tip) — later phases prove no content was lost against it, and it's the exact ref to restore from if the user ever wants to roll back:
# rollback, if ever needed:
git push --force <repository-url> OLD_SHA:refs/heads/<branch>
Report the backup's absolute path. Never delete it as part of this skill.
A force-push does not remove a leaked secret: it survives in forks, in the host's dangling-commit cache, and in anyone's existing clone. Finding one now changes the plan from "rewrite" to "rewrite and rotate."
Clone a normal (non-mirror) working copy — you'll reuse it for the squash:
git clone <repository-url> <work>
cd <work>
git checkout <branch>
If gitleaks is available:
gitleaks git . --no-banner
gitleaks git scans commit history — that is the command this step needs. gitleaks directory . scans the working tree instead and would miss committed-then-removed keys, which are exactly what a history rewrite is usually about. On gitleaks older than 8.19 the spelling is gitleaks detect --source . --no-banner; 8.19 renamed detect → git and detect --no-git → directory, keeping the old names working but hidden from --help..gitignored paths, so a secret in secrets/ or *.local is unscanned either way; say so rather than reporting a blanket clean.gitleaks → state that history was not scanned and recommend installing it if secrets in old commits are a concern: winget install gitleaks (Windows), brew install gitleaks (macOS/Linuxbrew), the distro package on Linux (apt install gitleaks, pacman -S gitleaks, dnf install gitleaks), or a release binary from the project's GitHub releases where the distro has none.In the working clone, on the target branch:
git checkout --orphan fresh
git add -A
git commit -m "<message>" # default: "Initial commit"
git branch -D <branch>
git branch -m fresh <branch>
Verify no content was lost — the whole point is a clean history over an identical tree:
git log --oneline # exactly one commit
git diff --stat <OLD_SHA> HEAD # MUST be empty — same tree as the old tip
If git diff <OLD_SHA> HEAD shows anything, stop: the squash changed the file tree (usually an untracked or ignored file that git add -A did or didn't pick up). Do not push a tree that differs from what was there.
Use --force-with-lease, not a bare --force: it aborts if someone pushed to <branch> after your clone, so you never silently overwrite a commit you never saw.
git push --force-with-lease=<branch>:<OLD_SHA> origin <branch>
--force to steamroll it.refusing to allow an OAuth App to create or update workflow → the token lacks the workflow scope (Phase 0 step 6); the user refreshes it, then retry.Verify the remote tip is now the new commit:
git ls-remote origin <branch> # sha matches your new HEAD, not OLD_SHA
Drop the old objects from the working clone so it reflects the clean state:
git reflog expire --expire=now --all
git gc --prune=now --aggressive
Verify:
git rev-list --all --count # 1
git fsck --unreachable # old commits gone (empty or only expected)
The rewrite only touched <branch>. Any other branch or tag still points into the old history, which keeps those objects alive and the "clean history" incomplete.
git ls-remote --heads --tags origin
<branch> remains → nothing to do.git push origin --delete <branch-or-tag>
Deleting a tag orphans the release built on it — on GitHub and GitLab alike the release object and its notes/assets survive, but its tag link goes dead. Warn the user per tag before deleting, and note the tradeoff: keeping the tag leaves the old history reachable through it (the reset stays cosmetic for <branch>); deleting it completes the wipe but breaks the release.git remote prune origin
Never batch-delete refs. Never assume a tag is disposable.
Close with what happened, the evidence, and what the user must still do by hand:
Repository: <owner>/<repo> (branch <branch>)
Rewrite: <OLD_SHA> → <NEW_SHA> (N commits → 1)
Content: git diff <OLD_SHA>..<NEW_SHA> empty — tree identical, no files lost
Backup: <absolute path to *-backup-*.git> (verified: N commits, fsck clean)
Secret scan: clean | FINDINGS (rotate now) | not scanned (no gitleaks)
Verified: ls-remote tip = <NEW_SHA>; local rev-list = 1; fsck clean
Manual residuals (cannot be done by command):
--force-with-lease, never bare --force, so a concurrent push aborts you instead of being destroyed.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub khasky/awesome-agent-skills --plugin awesome-agent-skills49 skills in this plugin
/awesome-accessibility-auditRead-only WCAG audit of UI and markup with a concrete fix per finding. Use when asked to check accessibility, a11y, keyboard or screen-reader support, or contrast./awesome-agents-md-generatorMines a codebase's real commands, conventions and boundaries into an agent-agnostic AGENTS.md, nested per package in monorepos, every rule backed by counted evidence. Use when asked to write, generate or refresh AGENTS.md or agent instructions for a repo./awesome-api-designDesigns or reviews an HTTP API's shape before code: resources, versioning, pagination, idempotency, filtering. Use when asked to design an API or an endpoint.Other plugins' skills for the same job