| description | Use when migrating an existing forked repository into a clean upstream-vs-custom workflow while preserving non-conforming local work and existing divergence. |
|---|---|
| name | Fork Reorg |
| argument-hint | Fork URL, upstream URL, and any known local-only files or branches |
| agent | agent |
You are working inside an already-active forked repository.
The repository may already contain some non-conforming history, mixed customizations, local deployment files, direct commits on main, or partial remote/branch setup. Your job is to reorganize it into a durable fork workflow without losing existing work.
Set up this repository so that:
originpoints to the user's forkupstreampoints to the source repository- local
maintracksupstream/mainand remains upstream-clean going forward custom/mainbecomes the long-lived branch for fork-only divergence- upstream PR work happens on
contrib/<topic>branches - fork-only work happens on
custom/<topic>branches - fork-only files and policies are clearly mapped and documented for future agent sessions
- Do not lose, reset, overwrite, or silently discard existing user work.
- Do not use destructive git commands unless the user explicitly approves them.
- If the current repository state is messy or mixed, preserve it first and then reorganize around it.
- Prefer the smallest viable restructuring that creates a clean operating model.
- If repo-specific conventions exist, preserve them rather than imposing unrelated structure.
- If helper scripts are added, match the platform and tooling that the repository already uses.
- Inspect the current git state:
git remote -vgit status --short --branchgit branch -vv- check whether key local files are ignored by repo or global ignore rules
- Classify the current state before changing anything:
- upstream-safe work
- fork-only customizations
- mixed or ambiguous changes
- If the repo already contains mixed or non-conforming work, preserve it before reorganizing:
- create a safety branch if needed
- do not force-reset history
- do not assume
mainis clean
Implement a workflow equivalent to this model, adapted to the repository:
origin= user's forkupstream= source repomain= upstream-clean branch that tracksupstream/maincustom/main= long-lived branch for divergencecontrib/<topic>= upstream PR branchescustom/<topic>= fork-only branches
Create or update the minimal set of files needed so future agent sessions follow the same model:
- A fork mapping document such as
FORK-MAPPING.mdthat explains:- remote mapping
- branch roles
- fork-only files and directories
- rules for upstream-safe vs fork-only work
- daily sync workflow
- Agent instructions such as
AGENTS.mdor equivalent workspace instructions that state:- which remote is
origin - which remote is
upstream - that
mainstays upstream-clean - that
custom/mainis the long-lived divergent branch - that upstream PRs must not include fork-only files
- that mixed requests should be split into separate branches
- which remote is
- Helper scripts for routine fork workflows when appropriate, for example:
- syncing from upstream
- creating upstream PR branches
- creating custom branches
- Optional but recommended:
- fork-only automation only if it does not pollute an upstream-clean
main - if scheduled automation is needed, place it on a fork-only default branch such as
custom/main, or run it from an external controller repository instead of storing it onmain
- fork-only automation only if it does not pollute an upstream-clean
If the repo is already partially divergent or not following this structure:
- identify what should remain on
mainversus move tocustom/main - preserve user work before reshaping branches
- prefer additive migration over risky history surgery
- if history cleanup is required, stop and explain the tradeoff before proceeding
- if local deployment files, secrets paths, org-specific prompts, or environment-specific compose files exist, classify them as fork-only by default
Before finishing, verify all of the following:
- remotes are correctly mapped
- branch tracking is correct
- fork-only files are not accidentally hidden by ignore rules if they are meant to be tracked
- helper scripts have no obvious syntax errors
- any new workflow files are syntactically valid
- fork-only automation is not stored on an upstream-clean
main - the resulting policy is documented clearly enough that a future agent can continue without rediscovering intent
When done, provide:
- a short summary of what was changed
- the final remote and branch model
- any files created or updated for fork governance
- whether existing non-conforming work was preserved, moved, or left in place
- exact commands the user can run next
- any residual risk, especially if the repo started in a mixed or messy state
When in doubt, optimize for:
- preserving existing work
- separating upstream-safe changes from fork-only divergence
- making future agent behavior predictable
- avoiding hidden policy that lives only in chat instead of in repo files
Proceed with concrete repo changes when safe. If a destructive or ambiguous step is required, pause and ask only for that missing decision.