code-restack
Skill0 starsChanged 16 days agoApache-2.0View on GitHub
Rebase a stack of pushed part branches onto a new base, run the gates on each, check that every commit is signed, and push them with a lease. Use when the base of a stack moved (a part below merged, or main advanced) and the branches above must follow. Not for applying a Writer's patch files or squashing a part (see /code-integrate), or for syncing open pull requests.
- Commits and pushes
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- code-checkSkill
- code-formatSkill
- code-genSkill
- code-integrateSkill
- code-reviewSkill
- code-syncSkill
- code-testSkill
- commitSkill
- feat-discoverySkill
- feat-statusSkill
- feat-validateSkill
- releaseSkill
- code-rules-checkSkill
- code-rulesSkill
- docs-rules-checkSkill
- docs-rules-creatorSkill
- docs-rulesSkill
- skills-checkSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
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
- Very specific: line 23
Run on a clean working tree.
- Very specific: line 40
Only when every branch passed does it push them all in one atomic git push, each with a lease pinned to its origin/<branch> from before the …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Code Restack
One command that moves a stack of part branches onto a new base. It prints ONE compact JSON result and writes the
raw git and gate output to a log file, named in the result as log; read the log only when the result says
something failed.
When to Use
- A part below the stack merged, or the stack's base advanced, and every branch above must be rebased.
The script never resolves a conflict, never pushes an unsigned commit, never uses plain --force, and never merges
or closes a pull request.
Command
Run on a clean working tree. --repo names the repository and defaults to the current directory, so the call
needs no cd.
python3 <repo>/.agents/skills/code-restack/scripts/restack.py --repo <repo> --onto origin/main --from <old-base> lnsd/<slug>-1 lnsd/<slug>-2 ...| Argument | Meaning |
--repo | The repository to work in; default the current directory |
--onto | The ref the bottom branch moves onto, such as origin/main |
--from | The ref the bottom branch sits on now: its old base, or the tip of the part that merged |
<branch>... | The part branches, bottom to top, as named on the remote |
It fetches, then rebases each branch from its origin/<branch> with git rebase --onto, bottom to top, each one
onto the rebased tip of the branch below. After each rebase it runs the gates fmt-check, check, typecheck,
test and check-docs, stopping at the first failure, and checks that every commit is signed (%G? is G).
Only when every branch passed does it push them all in one atomic git push, each with a lease pinned to its
origin/<branch> from before the rebase, and then move the local branches. Until then no local branch moves and
nothing is pushed. A local branch that another worktree has checked out is not moved, since git refuses to; the
run is still ok, because the remote moved, and the branch is listed in local_not_moved.
It refuses when --repo is not a git repository, when the tree is not clean, when a ref does not exist, when a
branch does not sit on the one below it, when a local branch holds commits its remote branch lacks, and when the push
is rejected, in which case no remote branch moved.
Result
{"status":"ok","stack":[{"branch":"lnsd/x-1","old_sha":"…","new_sha":"…","gates":{"fmt-check":"pass"},"push":"lease"}],"local_not_moved":[],"log":"…"}statusisok,needs_rebase(with thebranchthat conflicted; the rebase was aborted),gates_failed(with thebranch; its failed gate isfailand later gates did not run),refusedorerror.local_not_movedlists the branches whose local copy stayed at its old tip because another worktree holds it.refusedanderrorcarry areason.
Exit codes
| Code | Meaning | What the caller does |
| 0 | ok | Continue |
| 1 | A gate failed | Read the log, send the failure back as a FIX |
| 2 | A rebase conflicted and was aborted | Ask the Writer for a REBASE of the named branch |
| 3 | Refused or a git command failed | Read reason; fix the setup, do not work around it |
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.

