git-recovery
Skill0 starsChanged 25 days agoMITView on GitHub
Use when Git work appears lost: commits after a hard reset, a deleted branch, a bad rebase or merge, a dropped stash, detached HEAD commits, a force-pushed remote, or overwritten files. Provides reflog and fsck recovery steps with backups and safety gates. Does not rewrite shared history without coordination.
- Deletes or force-pushes
- Commits and pushes
5 other projects use a version of this.
Adopted by
Most recently taken up by
- d4rken/clankermuxtheir own version, first seen Nov 2, 2026
- gabrielbauman/skillstheir own version, first seen Nov 1, 2026
- Indium-AI-Labs/indium-agentkittheir own version, first seen Nov 1, 2026
- Ionate-Technologies/indium-agentkittheir own version, first seen Oct 20, 2026
- dagarre00/claude-code-templatetheir own version, first seen Oct 15, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- Indium-AI-Labs/indium-agentkit★ 18same name
- Ionate-Technologies/indium-agentkit★ 17same name
- d4rken/clankermux★ 11same name
- dagarre00/claude-code-template★ 1same name
- gabrielbauman/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository18 other files it gives its agents.
- docs/agents.mdAGENTS.md
- agent-skill-authorSkill
- api-contract-reviewSkill
- codex-cli-workflowsSkill
- codex-plugin-authorSkill
- context-budgetSkill
- dependency-auditSkill
- docs-writerSkill
- incident-postmortemSkill
- mcp-server-builderSkill
- performance-profileSkill
- pr-reviewerSkill
- release-engineerSkill
- repo-onboardingSkill
- skill-security-reviewSkill
- sql-migration-reviewSkill
- terminal-debuggerSkill
- test-first-fixSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
23 rules. 0 are common, 21 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
21
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 22
Use this skill when:
- Distinctive: line 35
Stop: Do not run git gc, git prune, git reflog expire, or another reset.
- Distinctive: line 58
Look for the line before the reset.
- Distinctive: line 64
Create a safety branch at that commit:
- Distinctive: line 81
When you find the tip:
- Distinctive: line 87
If the branch was deleted on the remote but still exists locally:
- Distinctive: line 93
If the branch was deleted on the remote and never existed locally, ask the hosting provider whether reflog or audit logs are available.
- Distinctive: line 103
After a completed rebase:
- Distinctive: line 111
Verify the branch content before moving the original:
- Distinctive: line 125
After a merge commit you want to undo:
- Distinctive: line 179
If you still have the old commits locally:
- Distinctive: line 223
After the editor and OS options are exhausted, look for build caches, test snapshots, and deployment artifacts.
- Distinctive: line 227
Commit before any rebase, reset, or checkout that can discard work.
- Very specific: line 228
Create a wip/ branch before risky experiments.
- Very specific: line 234
Use --force-with-lease, never bare --force.
- Distinctive: line 235
Keep a remote backup branch for long-lived work.
- Distinctive: line 236
Do not run git clean -fdx without checking what it will delete.
- Distinctive: line 260
Do not run garbage collection or prune during recovery.
- Distinctive: line 261
Do not reset a branch until the rescue branch is verified.
- Distinctive: line 262
Do not force-push a shared branch without explicit coordination.
- Distinctive: line 263
Do not assume a remote host keeps reflog forever.
- Distinctive: line 264
Do not paste repository contents or secrets into an external recovery service.
- Distinctive: line 265
Do not use git checkout -- .
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Recovery
Git rarely loses committed work immediately. It loses the references that make the work easy to find. Reflog entries and dangling objects usually survive until garbage collection.
The first rule is to stop making changes. Every new command can move a reference or trigger cleanup.
When to use
Use this skill when:
<!-- skillrig-ignore-block: dangerous-git -- failure-mode list; commands are described, not recommended -->git reset --hardremoved commits you still need.- A branch was deleted locally or on the remote.
- A rebase or merge went wrong.
- A stash was dropped or a conflict resolution was lost.
- You are in detached HEAD and made commits.
- A teammate force-pushed over your branch.
- Files were overwritten and never committed.
Golden rules
- Stop. Do not run
git gc,git prune,git reflog expire, or another reset. - Back up the repository, including
.git, before any recovery command. - Record the current state:
git status,git rev-parse HEAD,git reflog -20. - Recover into a new branch, not onto the branch you are trying to repair.
- Do not force-push shared history until the affected people agree.
- Prefer read-only commands until you have a candidate commit hash.
cp -a /path/to/repo /path/to/repo-recovery-$(date +%Y%m%d-%H%M%S)
cd /path/to/repo
git status
git rev-parse HEAD
git reflog -20On Windows, use File Explorer or robocopy to copy the folder while no Git command is running.
Workflow 1: recover commits after a hard reset
git reflogLook for the line before the reset. It looks like:
9f2c1ab HEAD@{3}: commit: add retry policyCreate a safety branch at that commit:
git branch rescue/retry-policy 9f2c1ab
git switch rescue/retry-policy
git log --oneline -5Then merge or cherry-pick what you need. Do not reset the original branch until the rescue branch is verified.
Workflow 2: recover a deleted branch
git reflog --all --date=iso | head -50
git branch --contains <candidate-sha>When you find the tip:
git branch rescue/deleted-branch <sha>If the branch was deleted on the remote but still exists locally:
git push origin rescue/deleted-branch:refs/heads/restored-branchIf the branch was deleted on the remote and never existed locally, ask the hosting provider whether reflog or audit logs are available. GitHub, GitLab, and Bitbucket expose different retention and APIs.
Workflow 3: recover from a bad rebase
During a rebase:
git rebase --abortAfter a completed rebase:
git reflog
# find "rebase (finish)" and the entry before it
git branch rescue/pre-rebase <sha-before-rebase>Verify the branch content before moving the original:
git diff <sha-before-rebase>..rescue/pre-rebase --statWorkflow 4: recover a merge
During a conflicted merge:
git merge --abortAfter a merge commit you want to undo:
git reflog
git branch rescue/pre-merge <sha-before-merge>To redo the merge cleanly, reset the branch to the pre-merge commit only after the rescue branch exists and you have confirmed the working tree is clean.
Workflow 5: recover detached HEAD commits
git reflog
git branch rescue/detached <sha>A commit made in detached HEAD is reachable through reflog until it expires. Create the branch before switching away or running cleanup.
Workflow 6: recover a dropped stash
git stash list
git reflog show refs/stash
git fsck --unreachable --no-reflogs | grep commitFor each candidate:
git show <sha> --stat
git stash apply <sha>git stash apply keeps the stash entry; pop removes it. Apply onto a clean tree.
Workflow 7: recover unreachable commits
git fsck --full --unreachable --no-reflogsThis lists dangling commits, trees, and blobs. For a commit:
git show --stat <sha>
git branch rescue/fsck <sha>git fsck --lost-found writes dangling objects into .git/lost-found/ for inspection. It does not restore references by itself.
Blobs without a commit are harder. Use git cat-file -p <blob> and inspect the content. Editor local history or IDE backups are often faster for uncommitted files.
Workflow 8: recover after a force-push
If you still have the old commits locally:
git reflog
git branch rescue/force-pushed <old-sha>
git push origin rescue/force-pushedThen coordinate with the person who force-pushed. Restoring the branch may discard their new work; merge both histories instead of overwriting one side.
For your own future force-pushes, use:
<!-- skillrig-ignore-block: dangerous-git -- force-with-lease is the safe form recommended here -->git push --force-with-leaseIt refuses to overwrite a remote branch that moved since your last fetch.
Workflow 9: recover overwritten files
Committed before overwrite:
git log --all --oneline -- path/to/file
git restore --source=<sha> -- path/to/fileStaged but not committed:
git fsck --unreachable --no-reflogs | grep blob
git cat-file -p <blob>Never committed:
- VS Code: Timeline or Local History.
- JetBrains: Local History.
- Vim: swap and undo files.
- macOS: Time Machine.
- Windows: File History or a previous version.
- Your editor's backup directory.
After the editor and OS options are exhausted, look for build caches, test snapshots, and deployment artifacts.
Prevention
- Commit before any rebase, reset, or checkout that can discard work.
- Create a
wip/branch before risky experiments. - Configure a longer reflog window:
git config --global gc.reflogExpire 180.days git config --global gc.reflogExpireUnreachable 60.days - Use
--force-with-lease, never bare--force. - Keep a remote backup branch for long-lived work.
- Do not run
git clean -fdxwithout checking what it will delete. Preview withgit clean -ndx. - Stash with a message:
git stash push -m "why".
Examples
Good first response to "I lost my commits":
git reflog -30
git branch rescue/lost-work <sha>
git show --stat rescue/lost-workBad first response:
<!-- skillrig-ignore-block: dangerous-git -- example of the wrong response, labelled Bad first response -->git reset --hard HEAD~3The second destroys more references before you know what exists.
Guardrails
- Do not run garbage collection or prune during recovery.
- Do not reset a branch until the rescue branch is verified.
- Do not force-push a shared branch without explicit coordination.
- Do not assume a remote host keeps reflog forever. Export the recovery branch promptly.
- Do not paste repository contents or secrets into an external recovery service.
- Do not use
git checkout -- .to "clean up" when files are missing. It overwrites the working tree.
Verification checklist
- Repository copied, including
.git. - Current HEAD and reflog recorded.
- Recovery target identified by hash and inspected with
git show. - Rescue branch created and checked out.
- Diff against the expected state reviewed.
- Tests run on the recovered branch.
- Original branch only moved after the rescue branch is safe.
- Remote restoration coordinated with affected people.
- Prevention step applied.
References
references/recovery-playbook.mdcontains a command-first incident sheet and provider notes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

