nesnilnehc/ai-cortex/integrate-branches

Claude Code and agent skill by nesnilnehc/ai-cortex

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

From the main repo on the main branch, scan all linked worktrees and local branches, let the user multi-select, then merge --no-ff + push them sequentially and clean up succeeded worktrees together.

Install

npx vskill@latest install nesnilnehc/ai-cortex/integrate-branches

SKILL.md

The same SKILL.md was published earlier as nesnilnehc/ai-cortex/integrate-branches.

Skill: Integrate Branches

Purpose

Wrap up feature branches in bulk from the main repository: scan every active linked worktree plus the local branches that have no worktree, let the user pick which ones land, check each working tree is clean, merge + push them one after another, then clean up every successfully merged worktree in one pass. It removes the cd into each directory followed by a manual delivery.


Core Objective

Primary goal: on the main repository's main branch, merge the branches the user selected (from a worktree or standalone) into main, push to origin, and clean up the worktrees that succeeded — leaving the repository in a known clean state.

Success criteria (all must be satisfied):

  1. ✅ Invocation context verified: CWD is the main repository root (not inside a linked worktree), and the current branch is the main branch
  2. ✅ All candidates discovered: both git worktree list --porcelain and git branch are parsed; the non-main entries are presented to the user as one list with type markers
  3. ✅ Pre-flight finished before any merge: every selected worktree entry was checked for a clean working tree; every dirty entry is reported together in one block
  4. ✅ Sequential merge + push: each selected clean branch is merged with --no-ff and pushed in turn; the status of each is recorded (succeeded / failed)
  5. ✅ Cleanup in one pass: every succeeded worktree entry is removed together; branch-only entries skip the worktree removal; failed entries get no cleanup at all
  6. ✅ Summary report emitted: the merge / push / cleanup / branch-deletion status of every branch is covered

Acceptance test: after the skill finishes, git log --oneline <main-branch> holds one merge commit per successful branch; git worktree list holds only the main repository plus the failed or skipped worktree entries; git ls-remote origin <main-branch> matches the local state.


Scope Boundaries

This skill does:

  • Verify the invocation context (main repository root + main branch)
  • Determine the main branch (auto-detected; the user is asked only when it cannot be determined)
  • Scan linked worktrees (git worktree list --porcelain) and local branches with no worktree (git branch)
  • Deduplicate: a branch already covered by a worktree entry is not shown twice
  • Let the user multi-select the branches to merge (all, or a subset by index)
  • Pre-flight the working tree: worktree entries through git -C <path> status --porcelain; branch-only entries skip the dirty check (they have no working tree of their own)
  • Run pull → --no-ff merge → push in turn for each selected branch
  • After each failure, ask the user: continue with the remaining entries, or abort
  • Clean up every successfully merged worktree entry in one pass (git worktree remove)
  • Optional feature-branch deletion (user-confirmed, -d only)
  • A per-branch summary report

This skill does not do:

  • Single-worktree delivery (use deliver-feature from inside the worktree)
  • Commit uncommitted changes (use commit-work inside each worktree first)
  • Rebase or squash before merging
  • Resolve merge conflicts (on a conflict it stops and reports to the user)
  • Create or manage pull requests
  • Force-push to any branch
  • Parallel merge execution (execution is always sequential)

Handoff points:

  • → `deliver-feature`: the user is inside a single worktree and wants to deliver only that branch, without a cd back to the main repository
  • Stop and prompt the user: invoked inside a linked worktree, or invoked on a non-main branch of the main repository
  • A branch hits a merge conflict: stop that one, and ask whether to continue with the rest
  • A branch's push is rejected: stop that one, and ask whether to continue with the rest

Use Cases

  • A developer has 2–4 feature branches (some in worktrees, some standalone) ready to land on main in one go
  • End-of-sprint wrap-up in bulk: merge, push, and clean up every finished feature branch from the main repository
  • A CI or automation run produced several parallel worktrees plus a handful of topic branches, and the results are now being consolidated

Behavior

Workflow (Checklist)

Step 1 — verify the invocation context

bash
git rev-parse --git-dir # main repo: <root>/.git ; linked worktree: <main-root>/.git/worktrees/<name>
git rev-parse --git-common-dir # same value in both contexts: <main-root>/.git
git rev-parse --abbrev-ref HEAD # current branch
git rev-parse --show-toplevel # current repository root

For a linked worktree git-dir != git-common-dir; in the main repository the two are equal.

  • If git rev-parse --git-dir differs from git rev-parse --git-common-dir (that is, CWD is inside a linked worktree) → stop:

> "This skill must run from the main repository root, not from inside a worktree. Current location: <cwd>. To deliver the current worktree's branch, use deliver-feature."

  • If the current branch is not the detected main branch (step 2) → stop:

> "The current branch is <current-branch>, not <main-branch>. Switch to the main branch first: git checkout <main-branch>."

Record <main-repo> (= git rev-parse --show-toplevel). CWD stays there for every step that follows.

Step 2 — determine the main branch

bash
git remote show origin | grep 'HEAD branch'
  • The result is unambiguous (such as HEAD branch: main) → use it directly.
  • The command fails or returns nothing → look for origin/main in git branch -r, then origin/master.
  • Still undetermined → ask the user:

> "The main branch could not be determined automatically. Enter the main branch name (main, master, develop, and so on):"

Record <main-branch>.

Step 3 — scan and present the selectable branches

bash
# Source 1: linked worktrees
git worktree list --porcelain
# Source 2: all local branches
git branch --format='%(refname:short)'

Parse the porcelain output. The first worktree record is the main repository itself — skip it. Record each of the others as a type: worktree candidate.

Exclude from the git branch output:

  • <main-branch> itself
  • Branches already covered by a worktree entry (deduplicated by branch name)

Record the remaining branches as type: branch candidates (with no associated worktree path).

Build one list of {path, branch, type} tuples. Skip detached entries and mark them unavailable.

  • No candidates → stop:

> "No active linked worktree or local branch was found; there is nothing to integrate."

Present the list with an index, a type marker, the path where applicable, the branch name, and a hint about recent activity:

text
Available branches to integrate:
[1] worktree /repos/myapp-auth feat/user-auth (last commit: 2 days ago)
[2] worktree /repos/myapp-api feat/api-v2 (last commit: 5 days ago)
[3] branch — feat/dashboard (last commit: 14 days ago — STALE)

If the user's request already names the branches or says all, use that selection. Otherwise ask:

"Select the branches to integrate. Enter the indexes (comma-separated) or all:"

Record <selected-list>.

Step 4 — pre-flight: check every selected entry

For each entry E in <selected-list>:

  • If E.type == worktree:

``bash git -C <E.path> status --porcelain ``

  • If E.type == branch: it has no working tree of its own — skip the dirty check and treat it as clean.

Collect the results into <clean-list> and <dirty-list> respectively.

If <dirty-list> is not empty, report every dirty entry together before any merge starts:

text
Pre-flight check — dirty worktrees (will be skipped):
/repos/myapp-api (feat/api-v2) — 3 uncommitted file(s)

Ask:

"The worktrees above hold uncommitted changes. Continue merging the remaining clean entries, or stop everything? [continue / halt]"
  • halt → stop; run no merges.
  • continue → carry on with <clean-list> only. If <clean-list> is empty → stop and report "nothing to act on".

Nothing is stashed automatically under any circumstances.

Step 5 — bulk merge + push (sequential)

For each entry E in <clean-list>:

bash
# stay current across a multi-branch run
git pull origin <main-branch>
# --no-ff merge
git merge --no-ff <E.branch> -m "Merge branch '<E.branch>' into <main-branch>"
# push
git push origin <main-branch>

CWD stays at <main-repo> throughout.

When entry E fails:

  • Merge conflict:

> "Merging <E.branch> into <main-branch> hit a conflict. Resolve the conflict in <main-repo>, finish the merge by hand, then push and remove the worktree where applicable."

  • Push rejected (not a fast-forward):

> "The push after merging <E.branch> was rejected. Run git reset --hard HEAD~1 in <main-repo> to undo the merge, then pull, merge again, and push."

In both cases mark E as failed and ask:

"Continue with the remaining branches, or abort everything left? [continue / abort]"
  • abort → stop; process none of the remaining entries.
  • continue → mark E as failed and move on to the next one.

Record the result of each one: succeeded or failed.

Step 6 — cleanup in one pass (worktree entries only)

Once all merges are done, confirm CWD is still <main-repo>:

bash
pwd # must equal <main-repo>

Only for the entries in <succeeded-list> where E.type == worktree:

bash
git worktree remove <E.path>

Run these in order. If one removal fails (the path no longer exists, say), record the error and move on to the next.

type: branch entries have no worktree path — this step skips them entirely. The worktree of a failed entry is never removed.

Step 7 — offer the local branch deletion option

For every entry in <succeeded-list>, present the branch list together:

"The successful entries are cleaned up. Delete the local feature branches below? Enter the indexes, all, or none:"
```text
[1] feat/user-auth (was worktree)
[2] feat/dashboard (was branch)
```

Once each one is confirmed, run:

bash
git branch -d <E.branch>

Use -d only — never -D. If -d fails, report the error and stop deleting that branch.

Step 8 — summary report

text
integrate-branches summary
──────────────────────────────────────────────────────────────────────────
Type Branch Merge Push Cleanup Branch-Del
worktree feat/user-auth ✓ ✓ ✓ deleted
worktree feat/api-v2 ✗(conflict) — — —
branch feat/dashboard ✓ ✓ — deleted
──────────────────────────────────────────────────────────────────────────
Main repo: /repos/myapp · Main branch: main · Remote: origin

Status codes: ✓ succeeded · ✗(reason) failed · skipped(dirty) pre-flight failed · — not applicable

The Cleanup column of a type: branch entry is always — (there is no worktree to remove).


Input & Output

Input Requirements
InputRequiredNote
Main repo + main branch contextYesCWD must be the main repository root, and the current branch must equal the main branch
Active candidatesYesAt least one linked worktree or local branch exists, other than main
Branch selectionUser inputall, or comma-separated indexes from the presented list
Clean working treePer worktree entryA dirty worktree is reported up front and skipped; branch-only entries always pass pre-flight
Main branch nameAuto / askDetected from the remote; the user is asked when it cannot be determined
Network accessYespull and push to origin need the network
Output Contract

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
7
Repository forks
3
7-day trend score
15

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/nesnilnehc/ai-cortex/integrate-branches/badge)](https://verified-skill.com/skills/nesnilnehc/ai-cortex/integrate-branches)

Something wrong with this skill or its page? Tell us.