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`.
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 skillInvocation 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 --hardandclean -fd
Install
npx skills@latest add smeltery/skillsOr copy just this skill:
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.mdUsage
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:
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:
- Create a fresh branch from the up-to-date default branch (
mainormaster, depending on the repo):bashDEFAULT_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 - 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:
git stash push -u -m "wip: <short description>"
# Switch to the target branch
git stash pop
# Commit the resultForce 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 --hardgit clean -fdgit rebase(prefer cherry-pick/merge)- Force pushes