nesnilnehc/ai-cortex/integrate-branches
Claude Code and agent skill by nesnilnehc/ai-cortex
- community
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-branchesSKILL.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):
- ✅ Invocation context verified: CWD is the main repository root (not inside a linked worktree), and the current branch is the main branch
- ✅ All candidates discovered: both
git worktree list --porcelainandgit branchare parsed; the non-main entries are presented to the user as one list with type markers - ✅ 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
- ✅ Sequential merge + push: each selected clean branch is merged with
--no-ffand pushed in turn; the status of each is recorded (succeeded/failed) - ✅ Cleanup in one pass: every
succeededworktree entry is removed together; branch-only entries skip the worktree removal; failed entries get no cleanup at all - ✅ 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-ffmerge → 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,
-donly) - A per-branch summary report
This skill does not do:
- Single-worktree delivery (use
deliver-featurefrom inside the worktree) - Commit uncommitted changes (use
commit-workinside 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
cdback 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
For a linked worktree git-dir != git-common-dir; in the main repository the two are equal.
- If
git rev-parse --git-dirdiffers fromgit 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
- The result is unambiguous (such as
HEAD branch: main) → use it directly. - The command fails or returns nothing → look for
origin/mainingit branch -r, thenorigin/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
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:
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) orall:"
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:
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>:
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→ markEasfailedand 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>:
Only for the entries in <succeeded-list> where E.type == worktree:
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, ornone:"```text[1] feat/user-auth (was worktree)[2] feat/dashboard (was branch)```
Once each one is confirmed, run:
Use -d only — never -D. If -d fails, report the error and stop deleting that branch.
Step 8 — summary report
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
| Input | Required | Note | |
|---|---|---|---|
| Main repo + main branch context | Yes | CWD must be the main repository root, and the current branch must equal the main branch | |
| Active candidates | Yes | At least one linked worktree or local branch exists, other than main | |
| Branch selection | User input | all, or comma-separated indexes from the presented list | |
| Clean working tree | Per worktree entry | A dirty worktree is reported up front and skipped; branch-only entries always pass pre-flight | |
| Main branch name | Auto / ask | Detected from the remote; the user is asked when it cannot be determined | |
| Network access | Yes | pull 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
- SKILL.md in the repositoryCheckingskills/integrate-branches/SKILL.md
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
[](https://verified-skill.com/skills/nesnilnehc/ai-cortex/integrate-branches)