plugins/developer-toolkit/skills/git/rebase-safely/SKILL.md
Use this skill when rebasing Git branches. Activate when the user mentions rebase, interactive rebase, squash commits, reorder commits, edit commit history, clean up commits before merge, rebase onto main, or fixing up commit history. Also use when rebase fails or causes conflicts.
npx skillsauth add latestaiagents/agent-skills rebase-safelyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Master Git rebase without losing work or causing team chaos.
NEVER rebase commits that have been pushed to a shared branch.
Rebasing rewrites history. If others have based work on those commits, you'll cause merge conflicts and confusion.
Safe to rebase:
✓ Local commits not yet pushed
✓ Your own feature branch (not yet merged)
✓ Commits only you have seen
NOT safe to rebase:
✗ main/develop branch
✗ Shared feature branches
✗ Already merged commits
# Fetch latest
git fetch origin
# Rebase onto main
git checkout feature-branch
git rebase origin/main
# If conflicts, resolve then:
git add <resolved-files>
git rebase --continue
# Force push YOUR branch only
git push --force-with-lease
# Rebase last 3 commits
git rebase -i HEAD~3
# Rebase from where branch diverged
git rebase -i main
Interactive rebase commands:
pick = use commit as-is
reword = use commit, but edit message
edit = use commit, but stop to amend
squash = meld into previous commit (keep message)
fixup = meld into previous commit (discard message)
drop = remove commit entirely
Before:
abc123 fix: typo in login
def456 fix: another typo
ghi789 feat: add login page
git rebase -i HEAD~3
Change to:
pick ghi789 feat: add login page
squash def456 fix: another typo
squash abc123 fix: typo in login
Result: One clean commit with combined message.
git rebase -i HEAD~3
Just change the order of pick lines:
pick ghi789 third commit
pick abc123 first commit # moved down
pick def456 second commit # moved down
git rebase -i HEAD~3
Change pick to edit for the commit you want to change:
pick abc123 first commit
edit def456 second commit # stop here
pick ghi789 third commit
Make your changes, then:
git add <files>
git commit --amend
git rebase --continue
git rebase -i HEAD~3
Change pick to reword:
pick abc123 first commit
reword def456 bad message # will prompt for new message
pick ghi789 third commit
git rebase -i HEAD~2
Mark commit as edit:
edit abc123 big commit to split
pick def456 next commit
Then:
# Undo the commit but keep changes
git reset HEAD^
# Create multiple commits
git add file1.js
git commit -m "feat: first part"
git add file2.js
git commit -m "feat: second part"
git rebase --continue
# See conflicted files
git status
# Resolve conflicts in each file
# Remove conflict markers (<<<<, ====, >>>>)
# Stage resolved files
git add <file>
# Continue rebase
git rebase --continue
# If it's too messy, abort
git rebase --abort
Understand both sides:
git show HEAD:<file> # Your version
git show REBASE_HEAD:<file> # Incoming version
Use merge tool:
git mergetool
Skip problematic commit (careful!):
git rebase --skip
# Create backup branch
git branch backup-feature-branch
# Make sure working directory is clean
git status
# Check progress
git status
# See what's being applied
git log --oneline REBASE_HEAD~1..REBASE_HEAD
# Compare with backup to ensure nothing lost
git diff backup-feature-branch feature-branch
# Delete backup when satisfied
git branch -d backup-feature-branch
| Aspect | Rebase | Merge | |--------|--------|-------| | History | Linear, clean | Preserves all commits | | Conflicts | Resolved per-commit | Resolved once | | Safe for shared branches | No | Yes | | Traceability | Less (rewrites) | More (merge commits) |
Use rebase for: Local cleanup, updating feature branches Use merge for: Integrating shared branches, preserving history
# Create a fixup commit for previous commit
git commit --fixup=<commit-to-fix>
# Autosquash during rebase
git rebase -i --autosquash main
The fixup commits automatically get positioned correctly.
# Find pre-rebase state
git reflog
# Look for entry like "rebase (start)"
# Find the commit BEFORE that
# Reset to pre-rebase state
git reset --hard HEAD@{5} # or specific SHA
# Immediately after rebase, ORIG_HEAD points to pre-rebase
git reset --hard ORIG_HEAD
--force-with-lease--rebase-merges## Rebase Policy
1. Rebase your feature branch onto main before creating PR
2. Never rebase after PR is opened (unless you're the only reviewer)
3. Squash fixup commits before merge
4. Use --force-with-lease, never --force
5. If unsure, ask before rebasing
development
Test skills for correct activation, content quality, and regression — both automated checks (frontmatter validity, lint) and manual verification (query-suite activation testing). Covers CI integration and how to catch skill regressions before users do. Use this skill when adding skills to a repo, setting up CI for a skill library, or debugging "the skill exists but doesn't work". Activate when: test skills, validate skills, skill CI, skill linting, skill activation test, skill regression.
documentation
Write the YAML frontmatter for a SKILL.md file so it activates reliably — name, description, and activation keywords that the model matches against. Covers length, tone, and the most common frontmatter mistakes. Use this skill when authoring a new skill, fixing a skill that isn't auto-activating, or reviewing skills for publication. Activate when: SKILL.md frontmatter, skill description, skill activation, skill YAML, write a skill, author a skill.
development
Design skills that fire at the right moment — neither over-eager (noise) nor under-eager (silent). Covers activation specificity, trigger phrases, disambiguation between overlapping skills, and debugging activation. Use this skill when multiple skills could fire on the same query, a skill never fires, or a skill fires too often. Activate when: skill won't activate, skill over-activates, overlapping skills, skill triggers, skill selection, skill disambiguation.
development
Structure SKILL.md content so the model reads just enough — concise summary up front, progressively deeper detail, examples on demand. Covers section ordering, length budgets, when to split into multiple skills. Use this skill when writing or refactoring a skill body, one skill has grown too long, or a skill is wordy but not useful. Activate when: SKILL.md structure, skill content, skill too long, split skill, progressive disclosure, skill body.