Non-negotiable rules:
- Check merge readiness before merging: branch state, CI, reviews, and conflict risk.
- Create a backup point before non-trivial merges or destructive recovery.
- Validate after merging before declaring success.
- Prefer isolated worktree execution for risky or explicitly isolated merges.
- Get explicit user confirmation before destructive rollback or branch cleanup.
Git Merge Expert
Inputs
$request: PR number, source branch, target branch, merge method, rollback target, or conflict-resolution goal
Goal
Perform safe git merges by:
- assessing readiness and merge method
- isolating risk when needed
- resolving conflicts without dropping intent
- validating the result
- cleaning up or rolling back safely
Step 0: Resolve the requested merge operation
Determine whether the user wants to:
- merge a PR
- merge one branch into another
- resolve conflicts from an in-progress merge
- assess merge readiness before executing
- roll back a bad merge
- clean up merged branches
If the requested scope, merge method, or cleanup behavior is ambiguous, use AskUserQuestion
before mutating git state.
Success criteria: The source, target, merge method, and cleanup expectations are explicit.
Step 1: Assess readiness and choose the execution mode
Inspect:
- current branch and working tree state
- source and target branch topology
- PR readiness when applicable
- CI and review status when applicable
- conflict likelihood
Then choose whether to:
- proceed inline for a straightforward merge
- route to
git-merge-expert-worktree for isolated execution
Prefer the worktree specialist when:
- the user explicitly asks for worktree isolation
- the merge is risky or multi-step
- cleanup/retry safety matters more than speed
Load references/merge-strategies.md for merge-method and readiness rules.
Success criteria: The merge is either blocked, approved for inline execution, or redirected to the worktree specialist.
Step 2: Create a backup point and perform the merge
Before non-trivial merges or destructive rollback, create a backup reference such as a tag.
Then perform the requested operation:
- PR merge via
gh when appropriate
- branch merge with the selected strategy
- conflict resolution for an in-progress merge
Rules:
- do not merge with failing CI unless the user explicitly wants to override
- do not silently drop either side of a conflict
- regenerate lockfiles instead of hand-editing them
- use the smallest safe merge method that matches the request
Load references/conflict-and-rollback.md for conflict tiers and recovery patterns.
Success criteria: The merge or conflict-resolution step is complete and git state is coherent.
Step 3: Validate before cleanup or push
Validate the result with the narrowest relevant checks:
git status
- conflict-free state
- build/test/typecheck commands when appropriate
- branch topology inspection
Rules:
- do not claim success if unresolved conflicts or failing validation remain
- stop and recover before cleanup or push when validation fails
- if rollback is needed, use the recovery guidance instead of improvising
Success criteria: The merge result is validated or the failure state is clearly identified.
Step 4: Report, clean up, or roll back safely
Depending on the result:
- report the merge outcome
- comment on the PR if needed
- clean up merged branches conservatively
- roll back using the safest method for the branch type
Rules:
- prefer
git revert over git reset on shared branches
- do not delete branches unless they are confirmed merged or the user explicitly asked
- warn before destructive cleanup or force-push operations
- if the merge was delegated to the worktree specialist, report that routing clearly
Load references/conflict-and-rollback.md for rollback and cleanup rules.
Success criteria: The user can see the outcome, any cleanup performed, and the remaining git state.
Guardrails
- Do not let the model invoke this skill proactively; it mutates git history and branch state.
- Do not add
context: fork; if isolation is needed, use the worktree specialist instead.
- Do not add
paths:; this is a generic git workflow skill.
- Do not keep giant examples, command encyclopedias, or long failure catalogs inline in
SKILL.md.
- Do not merge with unresolved conflicts.
- Do not delete user branches or force-push shared branches without explicit approval.
When To Load References
references/merge-expertise.md
Use at session start for role and domain expertise.
references/merge-strategies.md
Use for merge-method selection, PR readiness checks, GitHub CLI usage, and when to route to the worktree specialist.
references/conflict-and-rollback.md
Use for conflict tiers, lockfile handling, rollback choices, and cleanup rules.
Output Contract
Report:
- the requested merge or rollback operation
- the chosen execution mode and merge strategy
- the readiness/validation status
- any conflicts resolved, backup refs created, or rollback actions taken
- the final git state and any cleanup performed
1---2name: git-merge-expert3description: Run a git merge, PR merge, conflict resolution, or rollback safely — readiness-checked and BACKED UP before anything touches shared history. Assesses branch/CI/review state and conflict risk, tags a backup point before non-trivial merges, resolves conflicts without dropping either side (regenerating lockfiles, not hand-editing), validates the result, then cleans up or rolls back — routing to the worktree specialist when isolated execution is safer. Never claims success with unresolved conflicts or failing validation, prefers `git revert` over `reset` on shared branches, and requires explicit confirmation before destructive rollback, force-push, or branch deletion. Use only when the user explicitly asks to merge, resolve conflicts, or roll back.4---5
6<EXTREMELY-IMPORTANT>
7This skill mutates git state and must stay disciplined.
8
9Non-negotiable rules:
101. Check merge readiness before merging: branch state, CI, reviews, and conflict risk.
112. Create a backup point before non-trivial merges or destructive recovery.
123. Validate after merging before declaring success.
134. Prefer isolated worktree execution for risky or explicitly isolated merges.
145. Get explicit user confirmation before destructive rollback or branch cleanup.
15</EXTREMELY-IMPORTANT>
16
17# Git Merge Expert
18
19## Inputs
20
21- `$request`: PR number, source branch, target branch, merge method, rollback target, or conflict-resolution goal
22
23## Goal
24
25Perform safe git merges by:
26
27- assessing readiness and merge method
28- isolating risk when needed
29- resolving conflicts without dropping intent
30- validating the result
31- cleaning up or rolling back safely
32
33## Step 0: Resolve the requested merge operation
34
35Determine whether the user wants to:
36
37- merge a PR
38- merge one branch into another
39- resolve conflicts from an in-progress merge
40- assess merge readiness before executing
41- roll back a bad merge
42- clean up merged branches
43
44If the requested scope, merge method, or cleanup behavior is ambiguous, use `AskUserQuestion`
45before mutating git state.
46
47**Success criteria**: The source, target, merge method, and cleanup expectations are explicit.
48
49## Step 1: Assess readiness and choose the execution mode
50
51Inspect:
52
53- current branch and working tree state
54- source and target branch topology
55- PR readiness when applicable
56- CI and review status when applicable
57- conflict likelihood
58
59Then choose whether to:
60
61- proceed inline for a straightforward merge
62- route to `git-merge-expert-worktree` for isolated execution
63
64Prefer the worktree specialist when:
65
66- the user explicitly asks for worktree isolation
67- the merge is risky or multi-step
68- cleanup/retry safety matters more than speed
69
70Load `references/merge-strategies.md` for merge-method and readiness rules.
71
72**Success criteria**: The merge is either blocked, approved for inline execution, or redirected to the worktree specialist.
73
74## Step 2: Create a backup point and perform the merge
75
76Before non-trivial merges or destructive rollback, create a backup reference such as a tag.
77
78Then perform the requested operation:
79
80- PR merge via `gh` when appropriate
81- branch merge with the selected strategy
82- conflict resolution for an in-progress merge
83
84Rules:
85
86- do not merge with failing CI unless the user explicitly wants to override
87- do not silently drop either side of a conflict
88- regenerate lockfiles instead of hand-editing them
89- use the smallest safe merge method that matches the request
90
91Load `references/conflict-and-rollback.md` for conflict tiers and recovery patterns.
92
93**Success criteria**: The merge or conflict-resolution step is complete and git state is coherent.
94
95## Step 3: Validate before cleanup or push
96
97Validate the result with the narrowest relevant checks:
98
99- `git status`
100- conflict-free state
101- build/test/typecheck commands when appropriate
102- branch topology inspection
103
104Rules:
105
106- do not claim success if unresolved conflicts or failing validation remain
107- stop and recover before cleanup or push when validation fails
108- if rollback is needed, use the recovery guidance instead of improvising
109
110**Success criteria**: The merge result is validated or the failure state is clearly identified.
111
112## Step 4: Report, clean up, or roll back safely
113
114Depending on the result:
115
116- report the merge outcome
117- comment on the PR if needed
118- clean up merged branches conservatively
119- roll back using the safest method for the branch type
120
121Rules:
122
123- prefer `git revert` over `git reset` on shared branches
124- do not delete branches unless they are confirmed merged or the user explicitly asked
125- warn before destructive cleanup or force-push operations
126- if the merge was delegated to the worktree specialist, report that routing clearly
127
128Load `references/conflict-and-rollback.md` for rollback and cleanup rules.
129
130**Success criteria**: The user can see the outcome, any cleanup performed, and the remaining git state.
131
132## Guardrails
133
134- Do not let the model invoke this skill proactively; it mutates git history and branch state.
135- Do not add `context: fork`; if isolation is needed, use the worktree specialist instead.
136- Do not add `paths:`; this is a generic git workflow skill.
137- Do not keep giant examples, command encyclopedias, or long failure catalogs inline in `SKILL.md`.
138- Do not merge with unresolved conflicts.
139- Do not delete user branches or force-push shared branches without explicit approval.
140
141## When To Load References
142
143- `references/merge-expertise.md`
144 Use at session start for role and domain expertise.
145
146- `references/merge-strategies.md`
147 Use for merge-method selection, PR readiness checks, GitHub CLI usage, and when to route to the worktree specialist.
148
149- `references/conflict-and-rollback.md`
150 Use for conflict tiers, lockfile handling, rollback choices, and cleanup rules.
151
152## Output Contract
153
154Report:
155
1561. the requested merge or rollback operation
1572. the chosen execution mode and merge strategy
1583. the readiness/validation status
1594. any conflicts resolved, backup refs created, or rollback actions taken
1605. the final git state and any cleanup performed