Merge current branch to a target branch.
Input: The skill will prompt for the target branch name before executing.
Steps
Pre-merge checks
Run
git statusto check for:- Uncommitted changes (staged or unstaged)
- Untracked files
If there are uncommitted changes:
- Warn user and ask how to proceed:
- Stash changes and continue
- Commit changes first
- Cancel merge
Run
git branch --show-currentto get the current branch name.Run
git log origin/<current-branch>..HEAD --onelineto check if local is ahead of remote.If current branch not pushed to remote:
- Warn user: "Current branch has unpushed commits"
- Ask if they want to push first or proceed anyway
Get available branches
Run
git branch -ato list all available branches (local and remote).Show current branch and uncommitted changes status.
Prompt for target branch
Use AskUserQuestion tool to ask the user which branch they want to merge into.
Show:
- Current branch name
- List of common target branches (filtered from local branches)
- Allow custom input for other branch names
Example prompt:
当前分支: feature/xxx 未提交变更: 0 个文件 请选择目标合并分支: - master - qa - stg - 其他 (手动输入)Prompt for merge strategy
Use AskUserQuestion tool to ask for merge strategy:
Merge strategies:
- Default merge:
git merge <branch>- Standard merge with merge commit - Squash merge:
git merge --squash <branch>- Squash all commits into one - No-ff merge:
git merge --no-ff <branch>- Always create merge commit
Default: Standard merge
- Default merge:
Fetch and update target branch
Before merging, ensure target branch is up to date:
git fetch origin <target-branch> git checkout <target-branch> git pull origin <target-branch>Perform merge
Execute merge with selected strategy:
git merge <source-branch> -m "Merge branch '<source-branch>' into <target-branch>"Or with squash:
git merge --squash <source-branch> git commit -m "Merge branch '<source-branch>' into <target-branch> (squashed)"If merge conflicts occur:
- Show conflict files:
git diff --name-only --diff-filter=U - Show conflict summary
- Ask user how to resolve:
- Abort merge
- Manual resolve (wait for user to resolve)
- Use theirs/ours for specific files
If abort:
git merge --abortExit and inform user.
- Show conflict files:
Push to remote
After successful merge:
git push origin <target-branch>Switch back to source branch
IMPORTANT: Always switch back to the source branch after merge by default.
Return to the original branch:
git checkout <source-branch>Post-merge options (optional)
After switching back, ask user if they want to delete the source branch:
Options (multi-select):
- Keep branch (default): No action needed, continue development on source branch
- Delete local branch:
git branch -d <source-branch>(only if user explicitly selects) - Delete remote branch:
git push origin --delete <source-branch>(only if user explicitly selects)
Default behavior: Keep the source branch and continue working on it.
If user chooses to delete:
- Execute deletion commands
- Stay on target branch (since source branch no longer exists)
Display summary
Show:
- Source branch
- Target branch
- Merge strategy used
- Merge commit hash
- Files changed count
- Push status
- Branch deletion status (if applicable)
Output On Success
## Merge Complete
**Source:** <source-branch>
**Target:** <target-branch>
**Strategy:** Standard / Squash / No-ff
**Commit:** <merge-commit-hash>
<source-branch> ──► <target-branch>
**Changes merged:** <count> files (+<additions>, -<deletions>)
**Post-merge:**
- Source branch kept: Yes (default) / No (deleted)
- Switched back to: <source-branch>
**Remote:** <remote-url>
Output On Conflict
## Merge Conflict
**Source:** <source-branch>
**Target:** <target-branch>
**Conflicted files (<count>):**
- <file1>
- <file2>
**Options:**
1. Abort merge
2. Manual resolve (I'll wait for you to resolve)
3. Use "theirs" for all conflicts
4. Use "ours" for all conflicts
What would you like to do?
Merge Strategy Guide
| Strategy | Use Case | Pros | Cons |
|---|---|---|---|
| Standard | Feature branches | Preserves history | Multiple merge commits |
| Squash | Small features, WIP | Clean history | Loses individual commits |
| No-ff | Release branches | Clear merge point | Extra merge commit |
Guardrails
- Always check for uncommitted changes before merging
- Always check if source branch is pushed to remote
- Always prompt for target branch name before merging
- Always prompt for merge strategy
- Always fetch and pull target branch before merging
- Always switch back to source branch after merge (default behavior)
- Keep source branch by default, only delete if user explicitly requests
- Never force push without explicit user request
- Show clear summary of what happened
- Handle merge conflicts gracefully
Common Target Branches
When prompting, show these common branches if they exist:
master/mainqastgdevelop
Error Handling
- If uncommitted changes: Ask user how to proceed (stash/commit/cancel)
- If source branch not pushed: Warn and ask to proceed or push first
- If target branch doesn't exist: Show error and suggest available branches
- If merge fails with conflicts: Show conflicted files and prompt for resolution
- If push fails: Show error message and suggest resolution