finishing-a-development-branch

axiomantic's avatarfrom axiomantic

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 3, 2026

When & Why to Use This Skill

This Claude skill automates the final stages of the software development lifecycle by providing a structured, test-gated workflow for merging branches, creating GitHub Pull Requests, and cleaning up development environments. It ensures code quality by enforcing mandatory test passes before integration and offers a safe, autonomous way to handle branch completion and repository maintenance.

Use Cases

  • Automating GitHub Pull Request creation: Automatically pushes the feature branch and opens a PR with a structured summary and test plan after implementation is complete.
  • Safe local branch merging: Ensures all local tests pass before merging a feature branch into the main branch, and verifies the build again post-merge to prevent breaking the codebase.
  • Development environment cleanup: Automatically removes git worktrees and deletes merged or discarded branches to maintain a clean and efficient local workspace.
  • Autonomous workflow integration: Enables AI agents to independently decide on integration strategies (like auto-PR or stopping for review) based on pre-defined project settings.
namefinishing-a-development-branch
description"Use when implementation is complete, all tests pass, and you need to decide how to integrate the work"

Finishing a Development Branch

Release Engineer. Your reputation depends on clean integrations that never break main or lose work. A merge that breaks the build is a public failure. A discard without confirmation is unforgivable.

Announce: "Using finishing-a-development-branch skill to complete this work."

Invariant Principles

  1. Tests Gate Everything - Never present options until tests pass. Never merge without verifying tests on merged result.
  2. Structured Choice Over Open Questions - Present exactly 4 options, never "what should I do?"
  3. Destruction Requires Proof - Option 4 (Discard) demands typed "discard" confirmation. No shortcuts. No excuses.
  4. Worktree Lifecycle Matches Work State - Cleanup only for Options 1 (merged) and 4 (discarded). Keep for Options 2 (PR pending) and 3 (user will handle).

Inputs

Input Required Description
Passing test suite Yes Tests must pass before this skill can proceed
Feature branch Yes Current branch with completed implementation
Base branch No Branch to merge into (auto-detected if unset)
post_impl setting No Autonomous mode directive (auto_pr, offer_options, stop)

Outputs

Output Type Description
Integration result Action Merge, PR, preserved branch, or discarded branch
PR URL Inline GitHub PR URL (Option 2 only)
Worktree state State Removed (Options 1,4) or preserved (Options 2,3)

Autonomous Mode

Check your context for autonomous mode indicators:

  • "Mode: AUTONOMOUS" or "autonomous mode"
  • post_impl preference specified (e.g., "auto_pr", "offer_options", "stop")
post_impl value Behavior
auto_pr Skip Step 3 (present options), go directly to Option 2 (Push and Create PR)
offer_options Present options normally (this is the interactive fallback)
stop Skip Step 3, just report completion without action
(unset in autonomous) Default to Option 2 - safest autonomous choice. Document: "Autonomous mode: defaulting to PR creation"
**Circuit breakers (always pause):** - Tests failing - NEVER proceed - Option 4 (Discard) selected - ALWAYS require typed confirmation, never auto-execute

The Process

Step 1: Verify Tests

Before presenting options: - Do tests pass on current branch? - What is the base branch? - Am I in a worktree?
# Run project's test suite
npm test / cargo test / pytest / go test ./...

If tests fail:

Tests failing (<N> failures). Must fix before completing:

[Show failures]

Cannot proceed with merge/PR until tests pass.

STOP. Do not proceed to Step 2.

If tests pass: Continue to Step 2.

Step 2: Determine Base Branch

# Try common base branches
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

Or ask: "This branch split from main - is that correct?"

Step 3: Present Options

Present exactly these 4 options:

Implementation complete. What would you like to do?

1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work

Which option?

Don't add explanation - keep options concise.

Step 4: Execute Choice

Option 1: Merge Locally

# Switch to base branch
git checkout <base-branch>

# Pull latest
git pull

# Merge feature branch
git merge <feature-branch>

# Verify tests on merged result
<test command>

# If tests pass
git branch -d <feature-branch>

Then: Cleanup worktree (Step 5)

Option 2: Push and Create PR

# Push branch
git push -u origin <feature-branch>

# Create PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>

## Test Plan
- [ ] <verification steps>
EOF
)"

Then: Cleanup worktree (Step 5)

Option 3: Keep As-Is

Report: "Keeping branch . Worktree preserved at ."

Don't cleanup worktree.

Option 4: Discard

**Confirm first with explicit typed confirmation:** ``` This will permanently delete: - Branch - All commits: - Worktree at

Type 'discard' to confirm.


Wait for exact confirmation. Do NOT proceed on partial match.
</CRITICAL>

If confirmed:
```bash
git checkout <base-branch>
git branch -D <feature-branch>

Then: Cleanup worktree (Step 5)

Step 5: Cleanup Worktree

For Options 1, 2, 4:

Check if in worktree:

git worktree list | grep $(git branch --show-current)

If yes:

git worktree remove <worktree-path>

For Option 3: Keep worktree intact.


Quick Reference

Option Merge Push Keep Worktree Cleanup Branch
1. Merge locally Yes - - Yes
2. Create PR - Yes Yes -
3. Keep as-is - - Yes -
4. Discard - - - Yes (force)

Anti-Patterns

- Proceeding with failing tests - Merging without post-merge test verification - Deleting branches without typed "discard" confirmation - Force-pushing without explicit user request - Presenting open-ended questions instead of structured options - Cleaning up worktrees for Options 2 or 3 - Accepting partial confirmation for Option 4

Self-Check

Before completing: - [ ] Tests pass on current branch - [ ] Tests pass after merge (Option 1 only) - [ ] User explicitly selected one of the 4 options - [ ] Typed "discard" received (Option 4 only) - [ ] Worktree cleaned only for Options 1 or 4

IF ANY unchecked: STOP and fix.


Integration

Called by:

  • executing-plans (Step 5) - After all batches complete
  • executing-plans --mode subagent (Step 7) - After all tasks complete in subagent mode

Pairs with:

  • using-git-worktrees - Cleans up worktree created by that skill