karfly

wt-merge

0
0
# Install this skill:
npx skills add karfly/agent-skills --skill "wt-merge"

Install specific skill from multi-skill repository

# Description

Create a pull request from the current git worktree branch to its parent branch. Use when a user wants to merge their worktree feature branch back to the branch it was created from. Determines the parent branch from git config, asks the user if not found, then creates a PR for review.

# SKILL.md


name: wt-merge
description: Create a pull request from the current git worktree branch to its parent branch. Use when a user wants to merge their worktree feature branch back to the branch it was created from. Determines the parent branch from git config, asks the user if not found, then creates a PR for review.
metadata:
short-description: Create PR from worktree to parent branch


Worktree Merge (PR)

Overview

Create a pull request from the current worktree's feature branch to its parent branch (the branch it was originally created from).

Parent branch info is stored in git config branch.<branch>.parent.

Prerequisites

  • Require GitHub CLI gh. Check gh --version. If missing, ask the user to install it.
  • Require authenticated gh session. Run gh auth status. If not authenticated, ask the user to run gh auth login.
  • Must be inside a git repository (can be a worktree).

Workflow

  1. Verify environment
  2. Run gh auth status to confirm GitHub CLI is authenticated.
  3. Run git rev-parse --is-inside-work-tree to confirm we're in a git repo.

  4. Get current branch

  5. Run git branch --show-current to get the current branch name.

  6. Determine parent branch

  7. Try to read parent from git config: git config branch.<current-branch>.parent
  8. If parent is not set, ask the user which branch to merge into (common options: main, master, develop).
  9. Confirm the parent branch exists: git rev-parse --verify <parent-branch>

  10. Check for uncommitted changes

  11. Run git status --porcelain
  12. If there are uncommitted changes, warn the user and ask if they want to continue or commit first.

  13. Push current branch

  14. Ensure the current branch is pushed to remote: git push -u origin $(git branch --show-current)

  15. Show summary and ask for confirmation

  16. Display:
    • Current branch name
    • Parent/target branch name
    • Number of commits ahead of parent: git rev-list --count <parent>..<current>
    • Brief diff stat: git diff --stat <parent>..HEAD
  17. Ask user to confirm before creating PR.

  18. Create pull request

  19. Run: gh pr create --base <parent-branch> --head <current-branch> --fill
  20. If --fill produces poor results, use --title and --body with a summary of changes.
  21. Output the PR URL to the user.

  22. Optionally save parent for future

  23. If parent was manually specified, offer to save it: git config branch.<current-branch>.parent <parent-branch>

Example Usage

User: merge this worktree
Agent:
1. Checks current branch is `feat/auth-refactor`
2. Finds parent is `main` from git config
3. Shows: "Creating PR: feat/auth-refactor -> main (3 commits)"
4. Asks for confirmation
5. Creates PR and returns URL

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.