# Rebase Safely

> Rebase, squash, or rewrite history without losing work or breaking shared branches. Use before any history rewrite.

- Skill: `archive228/rebase-safely` (Agent Skill)
- Install (CLI): `npx skillmds@latest add archive228/rebase-safely`
- Raw SKILL.md: https://api.skillmd.com/api/skills/archive228/rebase-safely/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: archive228 (https://skillmd.com/u/archive228)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/archive228/rebase-safely

---

# Rebase Safely
1. **Backup first** — `git branch backup/<name>` before any rewrite. Free undo.
2. Rebase onto the latest base: `git fetch; git rebase origin/main`.
3. Resolve conflicts one commit at a time. Test after the rebase, not just that it "completed".
4. **Never rewrite shared history** — if others pulled the branch, rebasing it forces them into pain. Rewrite only your own un-pushed/un-shared commits.
5. Push with `--force-with-lease`, never bare `--force` (lease refuses if someone else pushed).
If anything goes sideways: `git reflog` finds the pre-rebase state; `git reset --hard backup/<name>` restores it.

