git-squash-rebase
Skill1 starsChanged 5 months agoMITView on GitHub
Squash-rebase stacked branches after a parent PR was squash-merged. Use when updating a child branch built on a merged parent, fixing duplicate parent commits after rebasing, or repairing a stacked PR workflow that is replaying old branch commits.
- Deletes or force-pushes
- Commits and pushes
In this repository8 other files it gives its agents.
- babysitSkill
- create-pull-requestSkill
- git-commit-generatorSkill
- marp-presentationsSkill
- plan-visualizerSkill
- pnpm-dependency-upgrade-auditSkill
- react-useeffect-guideSkill
- split-to-prsSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After a parent branch is squash-merged, main contains a new squash commit, not the parent's original commits.
- Very specific: line 23
Read it as: move <child-branch> onto <new-base>, bringing only commits after <old-parent-tip>.
- Distinctive: line 49
If the parent branch was deleted, moved, rebased, or recreated, ask for the old parent tip SHA or recover it from reflog / PR history …
- Distinctive: line 57
If the child branch has uncommitted changes, stash tracked and untracked files:
- Distinctive: line 65
Complete when: no uncommitted work can be overwritten by the rebase, or the user explicitly chooses another safe path such as committing it.
- Distinctive: line 119
If step 2 created a stash:
- Distinctive: line 148
Complete when: every commit and diff shown is intended child work.
- Distinctive: line 152
If the child branch was already pushed:
- Very specific: line 158
Do not use plain --force unless the user explicitly asks for it and accepts the risk.
- Distinctive: line 172
After F2 is moved, rebase F3 onto the new F2 while excluding the old F2 tip:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Squash-Rebase
Mental model
After a parent branch is squash-merged, main contains a new squash commit,
not the parent's original commits. A child branch still based on those original
commits must be moved with:
git rebase --onto <new-base> <old-parent-tip> <child-branch>Read it as: move <child-branch> onto <new-base>, bringing only commits after
<old-parent-tip>.
Workflow
1. Establish the boundary
Identify, without guessing:
<new-base>: usuallymain, but confirm the repo's base branch.<parent-branch>: the branch that was squash-merged.<child-branch>: the branch to update.<old-parent-tip>: the parent tip before the squash merge, or the commit where the child stopped being parent work and started being child work.- Working tree state: clean, dirty tracked files, and untracked files.
- Remote state: whether the child branch was pushed.
Useful probes:
git status --short
git branch --show-current
git rev-parse <child-branch>
git rev-parse <parent-branch> # only valid if it still points at the old parent tipIf the parent branch was deleted, moved, rebased, or recreated, ask for the old parent tip SHA or recover it from reflog / PR history before continuing.
Complete when: the base, child, old parent tip, working tree state, and remote push status are all known.
2. Protect local work
If the child branch has uncommitted changes, stash tracked and untracked files:
git stash push -u -m "before squash-rebase of <child-branch>"Skip this when the working tree is clean.
Complete when: no uncommitted work can be overwritten by the rebase, or the user explicitly chooses another safe path such as committing it.
3. Update the new base
git fetch origin
git switch <new-base>
git pull --ff-only origin <new-base>Complete when: the local <new-base> is up to date with its upstream.
4. Move the child with --onto
git rebase --onto <new-base> <old-parent-tip> <child-branch>This replays:
<old-parent-tip>..<child-branch>onto <new-base>. If the child has no commits of its own, it simply moves to the
new base.
Complete when: the rebase finishes, or it stops only on conflicts from the child's own commits against the updated base.
5. Resolve or abort
For expected conflicts:
git status
# edit conflicted files
git add <resolved-file>
git rebase --continueAbort if Git is replaying parent commits, the boundary is wrong, or the conflict set is clearly from already-merged parent work:
git rebase --abortComplete when: the rebase finishes with the intended child commits only, or it is aborted before rewriting the wrong history further.
6. Restore stashed work
If step 2 created a stash:
git switch <child-branch>
git stash popResolve stash-pop conflicts as ordinary working tree conflicts.
Complete when: any stashed work is restored or intentionally left in the stash with the stash reference noted.
7. Verify before pushing
# Should list only the child branch's own commits
git log --oneline <new-base>..HEAD
# Should show only intentional child differences
git diff --stat <new-base>...HEAD
# Optional boundary check
git log --oneline <old-parent-tip>..<child-branch>The old parent commit SHAs must not appear in <new-base>..HEAD. The squash
commit from the parent PR is already on <new-base>, so it should not appear
there either.
Complete when: every commit and diff shown is intended child work.
8. Push with lease protection
If the child branch was already pushed:
git push --force-with-lease origin <child-branch>Do not use plain --force unless the user explicitly asks for it and accepts the
risk.
Complete when: the remote child branch points at the verified rewritten history, or the user chooses not to push yet.
Deeper stacks
Work bottom-up. Before moving a branch, save the old tip needed by its child:
git rev-parse F2 # save as <old-F2-tip>After F2 is moved, rebase F3 onto the new F2 while excluding the old F2 tip:
git rebase --onto F2 <old-F2-tip> F3Repeat for each descendant. Each step is complete only when the next child's exclude boundary has been recorded before its parent is rewritten.
Pitfalls
git rebase --onto <new-base> <parent-branch> <child-branch>is safe only if<parent-branch>still points at the old parent tip.- A naive
git rebase <new-base>may replay parent commits. Abort it and restart with the correct--ontoboundary. - Dirty worktrees need a stash or commit before rebasing; include
-uwhen untracked files matter. - Multiple children require saving old tips before rewriting their parents.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

