Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
camacho avatar

Bail

  • 684 installs
  • 1 repo stars
  • Updated May 26, 2026
  • camacho/ai-skills

bail is a git bail-out skill that safely abandons a stuck branch or experiment while preserving hard-won lessons in a structured way for developers who need clean teardown without losing context.

About

bail is a skill from camacho/ai-skills that implements a reflect-first bail-out protocol for stuck branches and experiments. It detects the current step—from issue-only capture through worktree isolation to plan-on-branch stages—then reflects lessons, updates the GitHub Issue, closes open PRs, and cleans worktrees using absolute paths with git -C. Developers reach for bail when an experiment fails or stalls and they need structured teardown instead of leaving orphan branches, open PRs, and lost rationale. The skill sequences reflection before destructive cleanup so institutional knowledge lands in issues before branches disappear.

  • Detects current project step from 0 (Capture) through 8 (Ship) by scanning for artifacts
  • Always reflects first: writes reason, attempted work, and learnings to .branch-context.md
  • Consolidates lessons into MEMORY.md using a disposable clone to avoid polluting worktrees
  • Closes open PRs, cleans up worktrees and branches using only absolute paths and git -C
  • Bail-out protocol that turns every abandoned effort into documented institutional knowledge

Bail by the numbers

  • 684 all-time installs (skills.sh)
  • Ranked #617 of 3,282 Productivity & Planning skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/camacho/ai-skills --skill bail

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs684
repo stars1
Security audit3 / 3 scanners passed
Last updatedMay 26, 2026
Repositorycamacho/ai-skills

How do you safely abandon a stuck git branch?

Safely abandon a stuck branch or experiment while preserving hard-won lessons in a structured way.

Who is it for?

Developers using git worktrees and GitHub Issues who need a structured bail-out when an experiment or feature branch is stuck.

Skip if: Simple local branch deletes without issue tracking or teams that never use worktrees or pull requests.

When should I use this skill?

A branch experiment is stuck or abandoned and the developer wants reflect-first cleanup of worktree, PR, and GitHub Issue.

What you get

Updated GitHub Issue with lessons learned, closed pull request, deleted worktree, and removed experiment branch.

  • Updated GitHub Issue
  • Closed PR
  • Removed worktree and branch

Files

SKILL.mdMarkdownGitHub ↗

Bail-out protocol: always reflect FIRST, then clean up. All commands use absolute paths and git -C.

Inputs

  • WORKTREE: absolute path to current worktree (or primary if no worktree)
  • Optional reason string (if not provided, ask for one)

Steps

1. Detect current step by examining what exists:

What existsEstimated step
Just an issue, no branchStep 0 (Capture)
.branch-context.md, no worktreeStep 1 (Orient)
Worktree exists, no code changesStep 2 (Isolate)
Plan file on branchStep 3-4 (Design/Review)
Code changes committedStep 5-7 (Build/Verify/Archive)
PR open on GitHubStep 8 (Ship)

2. Prompt for reason if not provided.

3. Write learnings to .branch-context.md in the worktree:

   # Write bail context — use absolute path
   cat >> "$WORKTREE/.branch-context.md" <<EOF

   ## Bail
   - Reason: <reason>
   - What was attempted: <summary>
   - What was learned: <learnings>
   EOF
   git -C "$WORKTREE" add .branch-context.md
   git -C "$WORKTREE" commit -m "docs: capture bail context"

4. Consolidate learnings to MEMORY.md via disposable clone (never checkout main in a worktree):

   BAIL_DIR="${CLAUDE_SESSION_DIR:-$TMPDIR}/bail-reflect"
   [ -d "$BAIL_DIR" ] && rm -rf "$BAIL_DIR"
   git clone --depth 50 "$(git -C "$WORKTREE" remote get-url origin)" "$BAIL_DIR"

Read $BAIL_DIR/ai-workspace/MEMORY.md, append relevant learnings from .branch-context.md, then:

   git -C "$BAIL_DIR" add ai-workspace/MEMORY.md
   git -C "$BAIL_DIR" commit -m "docs: consolidate learnings from abandoned <branch>

   Co-Authored-By: Claude <model>"
   git -C "$BAIL_DIR" push

On non-fast-forward: git -C "$BAIL_DIR" pull --rebase then push. Max 3 retries. Clean up: rm -rf "$BAIL_DIR"

5. Update GitHub Issue (if accessible):

   GH_REPO=<owner/repo> gh issue comment <number> --body "Bailing: <reason>. Learnings captured in MEMORY.md."
   GH_REPO=<owner/repo> gh issue edit <number> --add-label "deferred" --remove-label "triage"

6. Close PR if open:

   PR_NUM=$(GH_REPO=<owner/repo> gh pr list --head "<branch>" --json number -q '.[0].number')
   if [ -n "$PR_NUM" ]; then
     GH_REPO=<owner/repo> gh pr close "$PR_NUM"
   fi

7. Ask about branch preservation:

Default: preserve the branch (user can resume later).

If user explicitly says delete — confirm by showing what will be destroyed:

   This will delete:
   - Branch: <name>
   - Worktree: <path>
   - Remote branch (if pushed)

   Type 'delete' to confirm.

Only after typed confirmation:

   PRIMARY="$(git -C "$WORKTREE" worktree list --porcelain | grep -m1 '^worktree ' | sed 's/^worktree //')"
   # Verify branch is merged before deleting (-d fails if unmerged, -D would force)
   git -C "$PRIMARY" worktree remove "$WORKTREE"
   git -C "$PRIMARY" branch -d <branch>

If branch -d fails (unmerged work), warn the user and stop. Do NOT use branch -D.

8. Done. Do not checkout main — stay in whatever CWD the session has.

Edge Cases

  • No worktree exists (bailing at Step 0-1) → skip worktree cleanup, just update issue
  • No GitHub access → skip issue update, still do local cleanup + memory consolidation
  • PR already merged → don't close, just note it in the output
  • No .branch-context.md → create one with just the bail reason before consolidating
  • CLAUDE_SESSION_DIR unset → fall back to $TMPDIR for clone

Output: Summary of what was cleaned up and where learnings were saved.

Related skills

FAQ

What does bail do before deleting a branch?

bail always reflects first—capturing lessons and updating the GitHub Issue—before closing open PRs and cleaning worktrees or branches with git -C and absolute paths.

How does bail detect the current experiment step?

bail inspects artifacts like open issues, .branch-context.md, existing worktrees, and plan files on the branch to estimate whether the experiment is at capture, orient, isolate, or design stages.

Is Bail safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.