Skip to content
Skills Library
Programming · Automation

backup-code

/backup-code

Create a safety backup before potentially destructive actions. Use when running risky git commands (reset, rebase, clean, restore, checkout with overwrite, force push), applying large sweeping edits, mass refactors, broad search-and-replace, generator rewrites, or any operation that may be hard to undo. Produces a recoverable snapshot via backup branch, stash, or both, and verifies recovery commands.

Repository
codebase ↗
Licence
MIT
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Create a safety backup before potentially destructive actions. Use when running risky git commands (reset, rebase, clean, restore, checkout with overwrite, force push), applying large sweeping edits, mass refactors, broad search-and-replace, generator rewrites, or any operation that may be hard to undo. Produces a recoverable snapshot via backup branch, stash, or both, and verifies recovery commands.

Arguments

/backup-code Describe what risky operation you are about to run and whether you prefer branch backup, stash backup, or both.
Original author description

Create a safety backup before potentially destructive actions. Use when running risky git commands (reset, rebase, clean, restore, checkout with overwrite, force push), applying large sweeping edits, mass refactors, broad search-and-replace, generator rewrites, or any operation that may be hard to undo. Produces a recoverable snapshot via backup branch, stash, or both, and verifies recovery commands.

How it works

  1. When to Use This Skill
  2. Risky Operations Covered
  3. Prerequisites
  4. Decision Flow
  5. Step-by-Step Workflow
  6. Completion Criteria
  7. Troubleshooting
  8. Notes
Original SKILL.md headings · 143 lines, 580 words
SKILL.md preview
---
name: backup-code
description: "Create a safety backup before potentially destructive actions. Use when running risky git commands (reset, rebase, clean, restore, checkout with overwrite, force push), applying large sweeping edits, mass refactors, broad search-and-replace, generator rewrites, or any operation that may be hard to undo. Produces a recoverable snapshot via backup branch, stash, or both, and verifies recovery commands."
user-invocable: true
argument-hint: "Describe what risky operation you are about to run and whether you prefer branch backup, stash backup, or both."
compatibility:
   environments:
      - vscode
      - github-copilot
      - copilot-cli
license: MIT
---

# Backup Code Before Risky Changes

Create a recoverable snapshot of local work before any potentially destructive operation.

## When to Use This Skill

- Before git operations that can discard or rewrite work
- Before large sweeping code changes across many files
- Before automated codemods, generator rewrites, or bulk renames
- Before cleanup commands touching untracked files
- Any time rollback confidence is low

Keywords: backup branch, safety checkpoint, stash snapshot, destructive git command, recover changes.

## Risky Operations Covered

- `git reset --hard`
- `git clean -fd` / `git clean -fdx`
- `git rebase` / `git rebase --onto`
- `git restore --source ... --worktree --staged`
- `git checkout` or `git switch` paths/branches that overwrite local work
- `git push --force` / `git push --force-with-lease`
- Large multi-file edits where undo history is insufficient

## Prerequisites

- Run from repository root
- Working tree state is inspectable with `git status --short`
- `git` is available

## Decision Flow

1. If current changes are meaningful and may be needed intact, create a backup branch snapshot.
2. If quick temporary rollback is needed, create a named stash.
3. If operation is highly destructive or uncertain, do both.
4. If no local changes exist, still create a backup branch for pre-operation baseline.

## Step-by-Step Workflow

### 1. Inspect Current State

Run:

```bash
git status --short
git branch --show-current
```

Record:

- Current branch name
- Whether there are tracked modifications
- Whether there are untracked files

### 2. Create Backup Artifact

Choose one strategy.

#### Strategy A: Backup Branch Snapshot (recommended)

```bash
iso_timestamp="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
current_branch="$(git branch --show-current)"
backup_branch="backup/${current_branch}/${iso_timestamp}"

git switch -c "$backup_branch"
git add -A
git commit -m "chore(codebase): 🔧 create safety backup before risky changes"
git switch "$current_branch"
```

Use this when you need a durable, auditable checkpoint.

#### Strategy B: Named Stash Snapshot

```bash
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
stash_name="backup:${timestamp}:before-risky-change"

git stash push --include-untracked -m "$stash_name"
```

Use this when you need a quick local rollback point.

#### Strategy C: Maximum Safety (both)

Run Strategy A first, then Strategy B if additional local-only checkpointing is desired.

### 3. Verify Recovery Paths

For branch backups:

```bash
git branch --list "backup/*"
```

For stash backups:

```bash
git stash list --date=local
```

### 4. Print Recovery Commands

Branch recovery:

```bash
git switch <backup-branch>
```

Stash recovery:

```bash
git stash apply "stash@{N}"
```

### 5. Proceed With Risky Operation

Only continue after backup artifact and recovery commands are confirmed.

## Completion Criteria

- Backup branch exists, or stash entry exists, or both
- Backup includes all intended tracked and untracked changes
- Recovery command is printed and verified
- Risky operation starts only after all checks pass

## Troubleshooting

| Problem | Cause | Fix |
| --- | --- | --- |
| `nothing to commit` on backup branch | No file changes staged | Keep branch as baseline checkpoint or proceed with stash-only if needed |
| `No local changes to save` from stash | Clean worktree | Create branch checkpoint only |
| Cannot switch branches | Ongoing merge/rebase/cherry-pick | Resolve or abort in-progress operation first, then create backup |
| Backup commit rejected by hooks | Strict hooks on commit | Use stash strategy for local checkpoint, then revisit backup commit approach |

## Notes

- Never use destructive commands before creating at least one checkpoint artifact.
- Prefer backup branch for long-running or high-risk tasks because it survives stash pruning and improves traceability.
- Backup branch naming convention: `backup/{branch_name}/{iso_timestamp}`.

Versions

The database has no other skills named backup-code.

Database snapshot: 13.11.2026 · package version 3b6a18023375 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100git-undo-recovery
    Recover from a git mistake - lost commits after `reset --hard`, a deleted branch, a commit made on the wrong branch, a bad merge or rebase, a dropped stash, a force-push that overwrote someone's work, files lost to `checkout .`, `restore` or `clean`. Use this whenever the user…
  • 90git-safety
    Git safety rules. INVOKE WHEN: git push, force push, git reset, git clean, destructive git, push force, reset hard. NEVER force push or do destructive git operations.
  • 100git-workflow
    Writes commit messages, manages branches, and opens pull requests with summaries. Use when the user asks to commit, push, branch, or create a PR, and before any destructive git operation such as reset, rebase, or force-push.
  • 100restore-code
    Restore code safely from backup artifacts created before risky changes. Use when undoing destructive operations, recovering from failed refactors or rebases, restoring deleted files, rolling back broad search-and-replace edits, or rehydrating work from backup branches and…
  • 100git-guardrails
    Install a hook, for one project or for every project, that blocks destructive git commands before an agent runs them: git push, force push, reset --hard, clean -f, branch -D, checkout . and restore . Claude Code's PreToolUse hook is the worked example. Use when the user wants to…
  • 100git-safety
    Stops an agent from destroying uncommitted work with git. Requires git status and git diff before any command that discards changes, treats "revert" and "undo" as manual edits, and never runs reset, checkout, clean, stash drop, or force push without explicit approval. Use when a…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.