---
name: finishing-a-development-branch
description: "Use when verified work needs integration or cleanup of an existing task-created branch/worktree, or the user explicitly requests merge, PR, or branch lifecycle handling."
title: finishing-a-development-branch
canonical_url: https://skilld.dev/gh/ganyuanran/aegis/finishing-a-development-branch
last_updated: 2026-10-12T05:05:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install ganyuanran/aegis/finishing-a-development-branch`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/finishing-a-development-branch`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/ganyuanran/aegis/finishing-a-development-branch) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/finishing-a-development-branch`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/finishing-a-development-branch --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/finishing-a-development-branch --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Finishing a Development Branch

## Overview

Integration choice and checkout lifetime are separate. Verify first, mutate only
task-owned resources, then prove what was removed or retained.

**Core principle:** fresh evidence -> authorized integration -> ownership-aware
cleanup -> Git/path readback.

**Announce at start:** explain which branch/worktree lifecycle is being closed.

## Step 1: Environment and Ownership Detection

Read the task's `TaskStartSnapshot` and current repository state. Record:

- root, `HEAD`, branch/detached state, upstream divergence, and active Git ops;
- staged/unstaged/untracked paths and the task-owned delta;
- `git worktree list --porcelain`;
- branch/worktree creator, task ownership, base branch, and cleanup trigger.

Stop on conflicts, unexplained detached state, failed verification, dirty/untracked state in
a cleanup target, or unknown ownership. Do not infer the base from the names
`main` or `master`; use task records, repository authority, or explicit user
direction. Never auto-stash, reset, clean, pull, rebase, amend, force-push, or
bypass hooks.

For a trusted host-managed detached checkout, follow the repository's approved
managed-workspace contract: verify host binding, default cwd, root, and HEAD;
then use its scoped local-commit and native handoff path. Report detached HEAD
in the receipt. This exception does not authorize automatic deletion of the
detached checkout or bypass unknown ownership/binding.

If no task-created branch/worktree exists and integration was not requested,
skip this workflow: report the local task commit plus `Task clean` and
`Repository clean`; do not invent merge/PR ceremony.

## Step 2: Fresh Verification

Run the smallest current-authority test set that proves the completed task. If
it fails, preserve all work and return to diagnosis. Do not present the branch
as ready.

## Step 3: Choose the Authorized Outcome

When a task branch actually needs disposition, present only applicable choices:

1. merge into the recorded base locally;
2. push and create/update a PR;
3. keep the branch for later integration;
4. discard the exact task-owned branch/worktree.

Push, PR, remote deletion, release, and force operations require explicit user
authorization. Discard requires a fresh, exact typed confirmation naming branch,
worktree path, and commits/delta to lose. Generic agreement is insufficient.

## Step 4: Execute Without Hidden Mutation

### Local merge

Verify the target checkout is safe, switch to the recorded base, merge without an implicit pull,
and rerun verification on the merged result. If integration
or verification fails, preserve both histories and stop.

### Push or PR

Push only the authorized task branch and create/update the PR with summary and
fresh test evidence. PR creation does not itself prove merge and does not
require the temporary worktree to remain.

### Keep branch

Retain the branch. Remove a clean task-created temporary worktree by default;
retain it only for an explicit ongoing-checkout need and report why.

### Discard

After exact confirmation, remove only the named clean task-owned worktree, then
the named branch. If either differs from the confirmation, stop and ask again.

## Step 5: Prove Integration Before Branch Deletion

Use evidence matching the merge strategy:

- merge/fast-forward: prove the task tip is an ancestor of the recorded base;
- squash/rebase: use fresh PR merge metadata plus strategy-appropriate patch
  equivalence (`git cherry` for rebased commits; stable patch-id or bounded
  changed-path/tree comparison for squashes), not an ancestor-only test;
- unmerged/open PR: keep the branch unless discard was exactly confirmed.

Never delete a branch merely because a PR was opened or a similarly named
commit exists.

## Step 6: Cleanup in Dependency Order

For a clean task-owned resource:

1. move to another safe registered checkout; never remove the current working directory;
2. remove/unregister the worktree first with `git worktree remove <exact-path>`;
3. read back `git worktree list --porcelain`;
4. verify the exact path no longer exists;
5. only then delete an integrated or exactly confirmed branch;
6. read back branch refs, `HEAD`, and repository status.

Do not use routine `--force`, global `git worktree prune`, wildcard deletion, or
cleanup of resources absent from the task ownership record. On Windows, Git may
unregister a worktree while its directory remains locked: re-check registration
and the exact resolved path, remove only a proven task-owned clean residual when
safe, otherwise retain it and report the lock/path. Never widen deletion scope.

## Final Git Receipt

Report:

- current branch and commit SHA/message, or the reason no commit exists;
- `Task clean: yes|no` and `Repository clean: yes|no` independently;
- branch/worktree created, removed, or retained, with evidence/reason;
- integration evidence and any remaining user action.

`Task clean` means no uncommitted task-owned delta remains. `Repository clean`
means no staged, unstaged, or untracked repository state remains.

This is a local Git receipt, not authoritative completion or merge truth beyond
the evidence read back.

## Integration

Called only when branch/worktree integration or explicit lifecycle handling is
in scope. Pairs with `using-git-worktrees` and
`verification-before-completion`.
