← Back to all skills

engineering / Git & commits

git-safety

Guards against destructive git operations — prefers stash + cherry-pick over rebase, restricts force pushes to `--force-with-lease`, and avoids `reset --hard` and `clean -fd`.

Markdown workflowYou or your agent

Put it to work.

Ask your agent to use git-safety, or let it load the skill when your task matches the description.

Use the git-safety skill

Invocation syntax varies by agent. Use the skill name in your prompt, or your agent’s supported slash command.

About this skill

Guardrails for safe git operations during active development.

  • Prefers stash + cherry-pick over rebase for moving work
  • Restricts force pushes to --force-with-lease
  • Avoids destructive defaults like reset --hard and clean -fd

Install

bash
npx skills@latest add smeltery/skills

Or copy just this skill:

bash
mkdir -p ~/.claude/skills/git-safety
curl -fsSL https://raw.githubusercontent.com/smeltery/skills/main/skills/engineering/git-safety/SKILL.md \
  -o ~/.claude/skills/git-safety/SKILL.md

Usage

Use when switching branches, moving work across branches, or deciding whether to rewrite history.

Files

  • SKILL.md — canonical skill definition.
Read the full SKILL.md

Core Principle

Prefer stash + cherry-pick to move work between branches. Avoid git rebase and force pushes unless absolutely necessary.

When switching context, stash first

If the working tree is not clean:

bash
git status
git stash push -u -m "wip: <short description>"

When you need to move work to a different base branch

Prefer replaying commits rather than rebasing a branch:

  1. Create a fresh branch from the up-to-date default branch (main or master, depending on the repo):
    bash
    DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
    git checkout "$DEFAULT_BRANCH"
    git pull origin "$DEFAULT_BRANCH"
    git checkout -b <type>/<branch-name>-v2
  2. Cherry-pick the relevant commit(s):
    bash
    git cherry-pick <sha1> <sha2> ...

When you have uncommitted work that needs to move

Convert it into a safe, transferable unit:

bash
git stash push -u -m "wip: <short description>"
# Switch to the target branch
git stash pop
# Commit the result

Force push policy

  • Default: do not force push.
  • If you must rewrite history:
    • Prefer opening a new PR from a new branch rather than rewriting an existing PR branch.
    • If you still must force push, use --force-with-lease (never plain --force).

Avoid these commands

Unless explicitly directed to do so:

  • git reset --hard
  • git clean -fd
  • git rebase (prefer cherry-pick/merge)
  • Force pushes

The Smeltery library

Find your next step.

Good places to start

smeltery / skills

A little direction goes a long way

What’s next?