Branch workflow

From bdfinst/agentic-dev-team · View interactive version

Branch workflow is an AI agent skill from the GitHub repository bdfinst/agentic-dev-team. Clean branch completion workflow — PR creation, merge strategy, and cleanup. Use this skill when implementation is complete and it's time to ship — after Phase 3 human gate passes. Also use when the user says "create a PR", "merge this", "ship it", "finish this branch", or asks about merge strategy.

How to use this skill

Skill file

Branch Workflow

Role: worker. This command performs PR creation, merge, and branch cleanup

directly via git/gh commands.

Overview

The three-phase workflow ends at the Phase 3 human gate. This skill formalizes what happens after approval: PR creation, merge decision, and branch cleanup. Without this, branches linger and merge conflicts accumulate.

Constraints

Workflow

1. Pre-PR Checklist

Before creating the PR, verify:

2. Create the PR

3. Present Options

After confirming the base branch, present exactly four choices. If this session entered a worktree via EnterWorktree for this branch, each option's cleanup step is performed with the paired ExitWorktree call below — never raw git worktree remove. If no worktree was entered via EnterWorktree (branch-workflow can also run directly in the primary checkout), the ExitWorktree steps are a no-op — skip them.

  1. Merge locally — Integrate feature branch into base, run tests on merged result, delete feature branch, then call ExitWorktree(action="remove"). In a lane, run the tests on the composed tree, then lane integrate, which replaces this option; see Lanes versus pull requests
  2. Push and create PR — Push branch and create pull request via gh pr create. Once the PR is opened, call ExitWorktree(action="keep") so the worktree persists on disk while the session's CWD bookkeeping is closed
  3. Keep as-is — Preserve branch and worktree for later handling; call ExitWorktree(action="keep") immediately after the option is confirmed — do not leave the worktree silently "entered" for the rest of the session
  4. Discard — Permanently delete branch and all commits. Requires the human to type "discard" to confirm. Never discard without typed confirmation. After confirmation, call ExitWorktree(action="remove", discard_changes=true)

3a. Pre-Switch Verification (Option 1 only)

Before performing the checkout/merge that Option 1 ("Merge locally") requires, verify the working tree is safe to switch:

  1. Run a working-tree status check (git status --short, or the worktree-tool equivalent) covering the feature branch's tree. This surfaces both tracked changes (modified/staged) and untracked files — not just tracked ones.
  2. Show the result to the human.
  3. If the tree is clean, proceed with the switch.
  4. If the tree is not clean (any modified, staged, or untracked files), stop. Do not switch branches silently. Require the human to explicitly say how to proceed — commit, stash, or abort — before running the checkout. This follows the same explicit-confirmation pattern as Option 4's typed "discard," not a bare warning that can be clicked through.
  5. Re-check that the target/base branch still matches what was confirmed in step 3's "After confirming the base branch..." — this does not re-ask for that confirmation, only verifies it hasn't drifted since.

This step applies only to the branch/worktree switch Option 1 performs. It does not replace or duplicate the Pre-PR Checklist's "Branch is rebased on latest main" item (§1) — that is a rebase-currency check performed earlier, not a dirty-tree check performed at the moment of switching. It also does not modify Post-Merge Verification & Cleanup (§5), which handles branch/worktree deletion after the merge, not the switch before it.

4. Merge Strategy (for options 1 and 2)

| Situation | Strategy | Why |

| ----------- | ---------- | ----- |

| Single logical change, clean history | Squash merge | One commit tells the story |

| Multiple logical changes that should stay separate | Merge commit | Preserves the history of each change |

| Long-lived branch with many commits | Squash merge | Reduces noise in main history |

| Experimental/spike work | Squash merge | The journey doesn't matter, only the result |

Default: squash merge unless the human specifies otherwise.

5. Post-Merge Verification & Cleanup

Lanes versus pull requests

Use a lane for repositories without PRs. A lane is a linked worktree and branch from the CODE0 skill. lane integrate fast-forwards local trunk only when the reviewed tree, the review gate, and the trunk commit still match. It removes the lane worktree and branch, and it never pushes.

Use /pr for GitHub repositories. lane integrate refuses when origin is on GitHub. To integrate locally anyway, pass --local-trunk.

Integration

Output

A merged PR with clean branch history, closed issues, and deleted feature branch.

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.