Finishing a development branch

From event4u-app/agent-config · View interactive version

Finishing a development branch is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when the feature is implementation-complete and the next step is 'ship it' — verifies, cleans up, routes to merge/PR/park/discard; never destroys work without explicit confirmation.

How to use this skill

Skill file

finishing-a-development-branch

When to use

Do NOT use when:

CODE0

commit + PR without the full gate

Goal

Route a finished branch to its next state with evidence — merged,

pushed for PR, parked, or discarded. Never let a half-verified branch

become a PR. Never destroy work without explicit confirmation.

The Iron Law

NO MERGE, NO PR, NO DISCARD WITHOUT VERIFIED TESTS + EXPLICIT CHOICE.

Skipping verification because "it worked a minute ago" is how broken

main happens. Discarding because "I assumed the user meant it" is

how work gets lost.

Procedure

1. Inspect the current branch state

Before presenting any options, gather context. Do not assume — check:

branch?

If a PR already exists for this branch, stop — this is not a

finishing step, route to CODE0

or CODE0 instead.

2. Verify readiness

Run the end-of-work gate before presenting any options — see

CODE0.

Steps 1–3 run only when quality.local_auto_run: true; under the

default (false / missing) skip them without asking — the user runs

quality tools manually, remote CI on the PR is the authoritative gate,

and the readiness report says "quality gates delegated to remote CI"

instead of claiming them green:

  1. Targeted tests green
  2. Full test suite green
  3. Quality pipeline green — the project's full sequence (type-checker → auto-fixer dry-run → linter → type-checker; e.g. PHPStan → Rector → ECS → PHPStan for Laravel-PHP, tsc → eslint --fix → eslint → tsc for TS, mypy → ruff --fix → ruff → mypy for Python)
  4. git status clean — nothing unstaged, no stray files
  5. Branch is pushed or explicitly marked local-only

If any executed step fails → stop. Report the failure, do not

present ship options. Fixing the failure comes first.

3. Determine the base branch

# Default: main
BASE=main

# Stacked PR: parent branch
BASE=$(git config branch.$(git branch --show-current).merge | sed 's|refs/heads/||')

If ambiguous, ask: "This branch splits from <guess> — correct?"

before presenting options.

4. Present the four options — numbered, no narration

Ask the user exactly one question:

Implementation is verified. What now?

1. Open a Pull Request on <base-branch>
2. Merge locally into <base-branch> (for projects without a PR flow)
3. Keep the branch as-is — I'll handle it later
4. Discard all work on this branch

Do not add recommendations unless the user asks. Each option leads to

a different sub-procedure (steps 5a–5d).

5a. Option 1 — Open a PR

  1. Ensure the branch is up to date with the base →

CODE0

  1. Self-review the full diff → CODE0
  2. Write the PR description → CODE0
  3. Open the PR → CODE0
  4. Confirm the PR opened green, not red

See CODE0 for

the surrounding discipline.

5b. Option 2 — Merge locally

Use only when the project policy is "no PR required" (solo repos,

spike branches, private tooling). For team repos, default to Option 1.

git checkout <base-branch>
git pull --ff-only
git merge --no-ff <feature-branch>
# Re-run the full test suite on the merged tree
<test command>
# Only if green:
git branch -d <feature-branch>

If the post-merge test run fails → git reset --hard ORIG_HEAD, fix

on the feature branch, restart from Option 1/2.

5c. Option 3 — Keep as-is

5d. Option 4 — Discard

Confirmation gate — require a typed answer, not "y":

This will permanently remove:
- Local branch <name>
- Remote branch <name> (if pushed)
- Commits: <list of SHAs + subjects>

Type "discard <name>" to confirm.

Only on exact match:

git checkout <base-branch>
git branch -D <feature-branch>
# Remove remote only if the user confirms a second time
git push origin --delete <feature-branch>

Log the discarded SHAs so the work can be recovered via git reflog

within the reflog TTL if needed.

6. Clean up worktrees

If the branch lives in a git worktree:

Output format

After the chosen option completes, report:

  1. What happened — single sentence ("PR #123 opened", "Merged

into main as abcdef", "Branch discarded")

  1. Evidence — exit codes / PR URL / commit SHA
  2. Cleanup state — worktree removed / kept, branch deleted /

retained

  1. Next step — e.g. "Awaiting review" / "Main is one commit ahead"

Gotchas

reviewable; check the CI status before reporting success

silently fails — the merge command aborts but the report can look

successful if the exit code is not checked

another local branch — the dependent branch is orphaned

line-comments — prefer additional commits during review

uppercase -D forces; only use -D inside the confirmed discard

flow

invalidates the stack

Do NOT

— the user decides

branch name

Anti-patterns

discard if you want" — buries the destructive option

create-pr — duplicates work. Trust the gate result if nothing

changed in between

When to hand over to another skill / command

CODE0,

CODE0

CODE0

Validation checklist

Before reporting "done" after this skill runs:

when quality.local_auto_run: true — under the default false

the report states "quality gates delegated to remote CI" instead

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.