Skip to content

docs: define branch and worktree lifecycle - #342

Merged
proerror77 merged 1 commit into
mainfrom
codex/branch-hygiene-policy
Jul 24, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/branch-hygiene-policy

Conversation

@proerror77

@proerror77 proerror77 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Change contract

Document verified branch and worktree lifecycle rules: auto-delete merged PR heads, classify closed-unmerged work, and review dirty worktrees before cleanup.

Out of scope

Business code, collector/runtime behavior, deployment, and automatic deletion of closed-unmerged branches.

Dependency or merge order

None; targets current main.

Focused validation

  • git diff --check
  • Independent policy review: approved.
  • Verified GitHub delete_branch_on_merge=true.

Rollout/rollback impact

Documentation and repository setting only. Revert this one commit to remove the written policy; the GitHub setting can be toggled independently.

Summary by CodeRabbit

  • Documentation
    • Added guidance for safely managing Git branches and worktrees.
    • Documented verification, cleanup, classification, and reporting steps for branch and worktree lifecycle operations.
    • Clarified safeguards for preserving changes in dirty worktrees before cleanup.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AGENTS.md adds a “Branch and Worktree Lifecycle” section defining procedures for branch deletion verification, stale reference pruning, closed-but-unmerged pull request classification, state capture, dirty worktree handling, and post-cleanup reporting.

Changes

Branch and Worktree Lifecycle

Layer / File(s) Summary
Lifecycle cleanup policy
AGENTS.md
Documents branch and worktree deletion checks, git fetch --prune, closed pull request classification, dirty-worktree safeguards, and required cleanup reporting.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely and accurately summarizes the main documentation change.
Description check ✅ Passed The description covers the required sections and includes contract, scope, validation, and rollback details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/branch-hygiene-policy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proerror77
proerror77 merged commit 3bc654a into main Jul 24, 2026
35 of 36 checks passed
@proerror77
proerror77 deleted the codex/branch-hygiene-policy branch July 24, 2026 08:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@AGENTS.md`:
- Around line 138-141: Update the branch/worktree deletion guidance to require
dirty-worktree commits be pushed to a named branch or PR, or otherwise
explicitly preserved outside the branch being deleted, before deletion. Retain
the existing requirements to review the changes and explicitly keep or discard
them.
- Around line 131-134: Update the branch cleanup guidance around
delete_branch_on_merge to recheck that the remote head branch still points to
the merged PR head before any manual deletion. Require explicit authorization
immediately before deleting it, and retain the existing git fetch --prune step
without altering local branches or worktrees.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 758fd063-25e0-41f9-930b-6b083683d934

📥 Commits

Reviewing files that changed from the base of the PR and between a674e41 and fa81543.

📒 Files selected for processing (1)
  • AGENTS.md

Comment thread AGENTS.md
Comment on lines +131 to +134
- Keep GitHub's `delete_branch_on_merge` enabled. After verifying a merge,
confirm that the remote head branch is gone; delete it manually only if
auto-delete did not run. Then use `git fetch --prune` to remove stale local
tracking refs without touching local branches or worktrees.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Verify the remote branch tip before manual deletion.

A merged PR’s head branch may have advanced or been reused after the merge. Require rechecking that the remote branch still points to the merged PR head, and obtain explicit authorization before deleting it; otherwise the fallback can remove unrelated post-merge work.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AGENTS.md` around lines 131 - 134, Update the branch cleanup guidance around
delete_branch_on_merge to recheck that the remote head branch still points to
the merged PR head before any manual deletion. Require explicit authorization
immediately before deleting it, and retain the existing git fetch --prune step
without altering local branches or worktrees.

Source: Learnings

Comment thread AGENTS.md
Comment on lines +138 to +141
- Before deleting a local branch or worktree, record its PR state, HEAD,
upstream/push state, and whether its worktree is clean. A dirty worktree
must be reviewed and either committed as its own contract, explicitly kept,
or explicitly discarded; never delete it merely to reduce branch count.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve dirty-worktree commits beyond local branch deletion.

“Committed as its own contract” is insufficient if the commit remains only on the branch being deleted. Require the changes to be pushed to a named branch/PR or otherwise explicitly preserved before deleting the branch or worktree.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AGENTS.md` around lines 138 - 141, Update the branch/worktree deletion
guidance to require dirty-worktree commits be pushed to a named branch or PR, or
otherwise explicitly preserved outside the branch being deleted, before
deletion. Retain the existing requirements to review the changes and explicitly
keep or discard them.

Source: Learnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant